Tell us what’s happening:
I suspect there might be a bug on the platform because my code fails on
The
sum
function should use the...
rest parameter on theargs
parameter.
but my code clearly includes the ...rest
parameter. I can back my code with Mozilla’s Javascript interpreter which outputted desired result.
Your code so far
function sum(...args) {
if (args.length == 0) {
return 0;
} else {
return args.reduce((previous, current) => {
return previous + current;
});
}
}
console.log(sum(1, 2, 3)); // 6
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0
.
Challenge: Use the Rest Parameter with Function Parameters
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters