OK, you are referring to the helper function passed into the reduce method, not the arguments passed into the sum function. These are two separate things and are not really related. It seems the issue here is that you don’t quite understand how the reduce method works. That’s OK, it can be a little tricky if you are not used to such things. In short, it helps you reduce the array down to a single value. But it doesn’t know how to do that so you have to pass in a helper function to tell it how.
The helper function technically takes four arguments but in practice you usually only use the first two, which are the accumulator and the current value. I can understand why using
b might be a little confusing because they aren’t very good descriptors for what they represent. So you can rewrite the helper function as:
(accumulator, currentValue) => accumulator + currentValue
The reduce method goes through each value in the array and applies the helper function to it. The accumulator value is the value returned from the previous call of the helper function. Since there is no previous call for the first array item, you pass in the starting value for the accumulator when you call reduce (that is what the second argument to reduce does, sets the accumulator to 0). The currentValue is the value of the array item that reduce is applying the helper function to.
So in my example above, reduce first applies the helper function to the first item in the array, which will return 1 because:
accumulator + currentValue for the first array item is
0 + 1
Remember that accumulator = 0 because that is the default value we passed in for it when calling the reduce method.
Then reduce applies the helper function to the second item in the array which will return 3 because:
accumulator + currentValue for the second array item is
1 + 2
Remember that accumulator now equals 1 because that is the value returned by the previous call to the helper function.
And this continues to the end of the array at which time reduce will return a single value.
If this is still not making sense feel free to add some console.logs inside of the reduce helper function so you can see what the values of the parameters are as reduce goes through the array.