Problems Flashcards

1
Q

Why doesn’t this work?

function sumAll(…numbers) {
return numbers.reduce((sum, num) => {sum + num}, 0);
}

console.log(sumAll(1234, 123))

A

curly brackets around sum and num make it a block and it needs return value then.

fix with:
function sumAll(…numbers) {
return numbers.reduce((sum, num) => sum + num, 0);
}

console.log(sumAll(1234, 123))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly