+4

can you expain this code ? I can't able to understand !

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)); // Answer is 12 but how ?

6/12/2019 1:52:04 PM

Injamul Mohammad Mollah

3 Answers

New Answer

+1

Do you understand Object and Array? function magic(...nums) { // the argument nums is [Object Array] in construction function let sum = 0; //sum ==0 nums.filter(n => n % 2 == 0).map(el => sum+= el); // from all elements in array any one n% 2 == 0 like 2 4 6 will be // .map el all elements still.in array will add to run finally 12 because 2 + 4 + 6 the last elements in nums here return sum; } console.log(magic(1, 2, 3, 4, 5, 6));

0

The answer: I dunno. Ask google. It didn't work for me.

0

This is magic code...you'll get headeck