Hello there !
I have trouble understanding the different parameters of the reduce callback function, look at this :
var array = [4,5,6,7,8];
var singleVal = 0;
// Only change code below this line.
singleVal = array.reduce(function(previousVal,currentVal){
return previousVal + currentVal;
}, 0);
I’m talking about “previousVal” and “currentVal”, can we just add whatever number of parameters, like I can put (previousVal,currentVal,afterVal,afterVal2,afterVal3) ?
And what they refer to ?
I mean when we are at the first iteration, it’s previousVal (= 0) + currentVal (= 4) right?
Thank’s if someone respond
(sorry for the grammar mistakes if there is).