Chapter "ES6: Use the Rest Operator .." solution fails if I use "args1" instead of "args"

Dear Team,

Chapter " ES6: Use the Rest Operator with Function Parameters" mentions about rest operator

In the solution if I rename “args” to “args1” it fails, please fix this.

Per my understanding user can give any name to function parameter which is prefixed with 3 dots.

Thanks,
Vikram

Did you use args1 when calling reduce? The same array name must be used otherwise you’ll get undefined.

Can you please share your code?


When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

The challenge instructed you to use args

It is not possible to test if you used the rest operator other than checking what you have written, as such it is not possible to let users use any name parameter they want - so the challenge asks you a specific parameter name

The challenge says “… Modify the function sum so that it uses the rest operator and it works in the same way with any number of parameters…”

It doesn’t mention not to change variable names, it is confusing for newcomers to JS like me. IMHO explicit instructions should be given here.

@newfoundglory @ArielLeslie below is the code which throws error

const sum = (function() {
  "use strict";
  return function sum(...args1) {
    return args1.reduce((a, b) => a + b, 0);
  };
})();
console.log(sum(1, 2, 3)); // 6

error

// running tests

The sum function uses the ... spread operator on the args parameter.

// tests completed

And if you don’t use args that test will not pass, as it says

Maybe it could be useful to add explicitly that thing also above, but it’s still there