- 2

ES6 Rest Parameters, 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));

30th Oct 2021, 2:23 AM
Kniffin Haruka
Kniffin Haruka - avatar
5 Answers
+ 6
Kniffin Haruka Why can't you? There's literally a web IDE built-in to SL. The code in question sums up all given elements which are even, so the output is 12 (2+4+6). https://code.sololearn.com/WgQ1M7h6uG2o/?ref=app
30th Oct 2021, 3:44 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Run it and see.
30th Oct 2021, 3:22 AM
Simon Sauter
Simon Sauter - avatar
+ 4
To do what Hatsy Rei did you can create a web code bit in the {} Code tab. Just add a new code, select web and save it ( be sure to click the public check box.) You can also tag someone to allow them access.
30th Oct 2021, 3:51 AM
Paul K Sadler
Paul K Sadler - avatar
0
If I can, I would not ask for help here
30th Oct 2021, 3:35 AM
Kniffin Haruka
Kniffin Haruka - avatar
- 1
12
16th Dec 2021, 11:21 AM
Nazma