0
What is the output of the following code? function magic (...nums) { let sum = 0; nums.filter(n=>n%2==0).map(el=>sum+=El);}
16 Antworten
+ 13
the answer is 12, it because with this "nums.filter(n=>n%2==0)" all the argumnets that are mod by 2 should be equal to 0 and with "map(el=>sum+=El" the all result return by the "nums.filter(n=>n%2==0)" will be added to each other. that's how i understand it, i am not really good at speaking english hope you get my point. :D
+ 8
Referencing to Nathaniel Baleña, it means that with ""map(el=>sum+=El", it will filter out the numbers that we get from the original array. We should get 2, 4 and 6. Then, simply add 2, 4 and 6 together to get 12.
+ 5
12
+ 4
I want to understand how and why the result is 12, I have failed to understand some one please help me
+ 3
answer is 12
+ 2
How
+ 2
right, the answer is: 12
+ 1
This should be 12
0
12
0
the answer is 12
0
answer is 12
0
12
0
answer is 12
0
12
0
answer is12
0
What will be the output? (Try it out. It’s tricky.)
const nums = [1,2,3,4,5];
let output = nums.filter(n => n%2);
console.log(output);