REST OPERATOR Test not passing

REST OPERATOR Test not passing
0

#1

Hello, Please am having issues passing this challenge on Rest Operator!
i have tried editing the code but it still doesn’t pass.
i keep getting this error message: The sum function uses the … spread operator on the args parameter..
this is my code so far:

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

AND

function sum(...arg){
  let args = arg.reduce((a,b)=>a+b, 0);
  return args
}
console.log(sum(1,2,3,));

Please need some suggestions/help


#2

This should be args and not arg.

Same thing over here as well.
This should do it.


#3

still throwing same error to me: The function sum uses the …spread bla bla bla
how did you pass yours? @aditya_p


#4

Could you post your latest code?
Cause changing the arg to args in your code passes the tests for me.


#5

ok… @aditya_p

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

#6

You don’t need to use these.
Just change this

to ...args.
Instruction clearly says:

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

Does this help?


#7

thanks…
it worked!!