ES6: Use the Rest Parameter with Function Parameters

Tell us what’s happening:
From one of the help post, I could get the code but I didn’t understand what does a and b signifies here.
Can someone please help me understand

Your code so far


const sum = (...args) => {
return args.reduce((a, b) => a + b, 0);
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

a is the accumulator (initial value set to 0 in this case) and b is the current element being processed.

You can check the docs for reduce and have a look at the fCC challenge on reduce.

MDN: Array.prototype.reduce()

Functional Programming: Use the reduce Method to Analyze Data

1 Like

Thank you for your reply, I watched a few videos on reduce which helped me understand the concept