JAVASCRIPT | SoloLearn: Learn to code for FREE!

0

JAVASCRIPT

What is the output of the following code? function magic(...nums) { let sum = 0; nums.filter(n => n % 2 == 0).map(el => sum+= el); return sum; } console.log(magic(1, 2, 3, 4, 5, 6)); please whats the output?

4/23/2020 11:35:31 AM

derah evah

4 Answers

New Answer

+1

What output did you got?

+1

There is code playground to check output

+1

0

Actually you overcomplicated a bit. Try to use "reduce" like: return nums.filter(n => n % 2 == 0).reduce((n1,n2) => n1+n2);