Skip to content
Advertisement

return a new array containing the results of passing the original elements into the callbacks in an alternating fashion

what should I do to get [3, 1.5, 15, 3.5, 27, 5, 63] output? Should I change the second for loops location ? Thanks in advance.

JavaScript

Advertisement

Answer

You could use only a loop with conditioned callback

JavaScript

JavaScript

Moreover, you could still use two loops like your current way, a slight change is to mutate the new array

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement