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 Answers
+ 1
What output did you got?
+ 1
There is code playground to check output
+ 1
12
0
Actually you overcomplicated a bit.
Try to use "reduce" like:
return nums.filter(n => n % 2 == 0).reduce((n1,n2) => n1+n2);