I finished the problem but it doesn’t explain much about the previousVal and currentVal. I thought the previousVal was the sum of the array so i figured it didn’t need a currentVal of 0 (zero). But i get an error when I remove the currentVal. I am curious as to why there are both the currentVal and previousVal as a parameter. Where to they come from specifically. Is the 0 in the argument the currentVal?
Thanks
Your code so far
var array = [4,5,6,7,8];
var singleVal = 0;
// Only change code below this line.
var sumOfArray = array.reduce(function(previousVal, currentVal) {
singleVal = previousVal + currentVal;
return singleVal;
}, 0);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Safari/604.1.38
.
Link to the challenge: