I’m mostly just looking for a clarification here.
In the following example…
const sumOfAges = users.reduce((sum, user) => sum + user.age, 0); console.log(sumOfAges); // 64
user are arguments in the call back function. In this case,
sum is known as the “accumulator” and
user is “current element being processed”. There are two other optional arguments:
- index of that element
- the array upon which
Finally, there is another (optional) parameter for the
reduce method: an initial value. In the case of the example, it is
Am I correct in summarizing that? Also, why do we refer to these things as arguments in the case of the callback function and parameters in the case of the reduce method?
Your browser information:
User Agent is:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0.
Challenge: Use the reduce Method to Analyze Data
Link to the challenge: