Using the Rest Operator with Function Parameters

Tell us what’s happening:

Hello guys, Please help with this. Am not getting it

Your code so far


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

Your browser information:

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

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

What do the failing tests say?

TypeError: unknown: Duplicate declaration “args”

args is declared when you write sum(...args)
Then when you write const args = [ x, y, z ]; you are attempting to redeclare something that already exists.

Ok, but then where does the rest operator come in

That is exactly what i did, …args

Ok, now i understand. Thought i wasnt supposed to touch their own code. Thanks a lot, you have been really helpful