const sum = (...a) => {
const args = [...a];
return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3, 4)); // 6
cant pass the last test
const sum = (...a) => {
const args = [...a];
return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3, 4)); // 6
cant pass the last test
You are not using an args
parameter. You have a parameter named a
.
The
sum
function should use the...
rest parameter on theargs
parameter.
instead your function has an a
parameter.
well i did this but gave me an error
SyntaxError: unknown: Identifier ‘args’ has already been declared
thanks fixed it…
When you use args as a parameter, you should not be declaring it again in your code. I would need to see the code you tried.