|
|
|
|
|
by jasonkester
1835 days ago
|
|
When used correctly it shouldn't produce any side-effects outside the mapping of each element. But that's just a social convention. There's nothing stopping you from doing other things during your map or reduce. In practice, the only difference between Map, Reduce and a For loop is that the first two return things. So depending on whether you want to end up with an array containing one item for each pass through the loop, "something else", or nothing, you'll use Map, Reduce or forEach. You can still increment your global counters, launch the missiles or cause any side effects you like. "using it correctly" and not doing that is just a convention that you happen to prefer. |
|
(and I haven't read the article so not even sure I agree with the example there, this was more in general terms)