Use the Rest Operator with Function Parametars

Tell us what’s happening:

 The code isn't  running

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-rest-operator-with-function-parameters/

Take a closer look at the test case you are failing.

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

you need to call it args instead of a.

1 Like

Thanks you helped me a lot. The things that is asked for is very weird.