ES6 - Use the Rest Parameter with Function Parameters

I dont understand why this test is failing: sum should be an arrow function which uses the rest parameter syntax (...) on the args parameter.

THE TASK - Modify the function sum using the rest parameter in such a way that the function sum is able to take any number of arguments and return their sum.

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



console.log(sum(2, 3, 4, 5, 6));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0

Challenge: ES6 - Use the Rest Parameter with Function Parameters

Link to the challenge:

notice the error shown for this code says:
sum should be an arrow function which uses the rest parameter syntax (...) on the args parameter.

The word args here must be used as the name of the parameter (not q)

2 Likes

Doh. Is that just an arbitrary condition here? There’s no tangible reason why I would have to use args as the name of the parameter, correct?

yes you can use any param name in real life.
Just so happens that this test wants you to use args.

Edit: though you probably should learn to use args for this anyway in my opinion because that’s kind of a standard name for multiple arguments.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.