DEV Community

Discussion on: We Don't Need No Stinking map() or filter()

Collapse
 
manelescuer profile image
Manel Escuer García

Using reduce instead of map won't be returning a new array on each iteration? Therefore lesser performance?

Collapse
 
jdsteinhauser profile image
Jason Steinhauser

In JavaScript, there would be a slight performance hit if you used reduce to perform a map operation because of returning an array each time. However, immutable data structures in other languages (like Clojure's vector) would not really see a performance hit because of how they are stored. You've given me an idea on a follow up post to discuss immutability and lazy vs. eager evaluation. Thanks for the feedback!

Collapse
 
manelescuer profile image
Manel Escuer García

Thank you!