Inquiry about "Use the Rest Operator with Function Parameters"

Tell us what’s happening:

Is that correct? I got 0 in the console, but the exercise doesn’t accept that solution.
My code so far


const sum = (function() {
  "use strict";
  return function sum(...args) {
    const result = [...args];
    const reducer = (acc, props) => acc + props 
    return result.length === 0 ?   "0" : result.reduce(reducer);

  };
})();
console.log(sum()); // 0

My browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15.

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

This check is not needed, it will also mess with the tests, you should leave it as it was

Here you are doing twice the same thing, creating result is unnecessary and can make you not pass. Just use args

1 Like

I see, thank you.

const sum = (function() {
  "use strict";
  return function sum(...args) {
    const result = [...args];
    return result.reduce((a, b) => a + b, 0);
  };
})();
console.log(sum()); // 0