I prefer to have readable code first, and performance improvement later and only if needed.
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(...)
is the more apt analog there as it wouldn't be generating a new array of the return like map would.
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.