Tell us what’s happening:
Error shows: addTogether(…) is not a function.
I make the spread array items as the parameters which I used many times before but now throws an error.
Thank guys very much for your answers.
Your code so far
function addTogether(...num) {
if (num.length === 1) {
if (typeof num !== 'number') {
return undefined;
} else {
return num2 => typeof num2 !== 'number'? undefined: num + num2;
}
} else {
for (let item of num) {
if (typeof item !== 'number') {
return undefined;
}
}
return num.reduce((a, b) => a + b);
}
}
console.log(addTogether(2, 3));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional