New course! Every coder should learn Generative AI!
Try a free lesson+ 3
Can anyone please help explain the science behind the output of this code?
function add(arr) { var a = arr.reduce(function(p, c) { return p + c; }) return a; } function multiply(arr, func) { var doubles = arr.map(function(n) { return n * n; }); return func(doubles); } var m = multiply([1,2,3,4], add); console.log(m); // output 30
8 Answers
+ 3
The output is 30.
The multiply function returns an array where each element is squared: [1,4,9,16].
The add function returns the sum of all array elements: 1+4+9+16 = 30.
+ 3
Oh, thank you ~ swim ~
+ 2
I wish you were correct Michael but your answer is not what SoloLearn gave as answer in the challenges section
+ 2
Honestly, ~ swim ~, SoloLearn are meant to make you a platinum Moderator
+ 2
Your level of knowledge ~ swim ~
+ 1
Michael and ~ swim ~, you can review this question here to see if I'm wrong or SoloLearn
https://www.sololearn.com/post/137749/?ref=app