by da39a3ee · 5y ago · 0 comments
Given that, isn't it odd that JS still encourages map/filter array iterations that make multiple passes over a single array? I.e. that it hasn't yet introduced some sort of comprehension or itertools-with-compilation feature that does array processing in a single pass?
A big reason why I say screw map, filter, reduce, etc. and my "default way" never stopped being ordinary for loops.
Array.map(e => f(e))
Easier to read than for(e in Array) {
f(e)
}
I don’t see how they really are any more or less readable, although I’ll admit map gave me a day of rethinking when I switched from 100% python to using react on the frontend. Array.forEach(e => f(e))
If you don't care about transformations. Which is basically the same as your forMap is when you want to return a new collection with each original item in it mapped to a "different" thing.
Array.forEach(...)
is the more apt analog there as it wouldn't be generating a new array of the return like map would.