It seems that functional iterators are replacing the use of for loops in JS.
What is the advantage of passing a function such as map
or reduce
compared to a for/while loop?
var numbers = [1, 4, 9];
var doubles = numbers.map(function(num) {
return num * 2;
});
var doubles = [];
for (i = 0; i < numbers.length; i++) {
doubles[i] = numbers[i] * 2;
}