DEV Community

Cover image for Map: Another Higher Order Function

Map: Another Higher Order Function

tiff on September 17, 2017

This was originally published on my blog. Map is another higher order function that goes through an array and doesn’t discard it but instead trans...
Collapse
 
washingtonsteven profile image
Steven Washington

Thanks for the run down! I feel like my array game is supercharged after learning about these array functions.

Collapse
 
tifflabs profile image
tiff

Yeah mine too. Working on refactoring a project and see many, many places I could use these functions.

Collapse
 
stefandorresteijn profile image
Stefan Dorresteijn

I'm pretty sure the map function is what I use most in any language. If you're working with data (especially from REST apis), you do so much data transforming that you really can't live without a map function.

Great post!

Collapse
 
jbbn profile image
João Bueno • Edited

Great post Tiffany!

In ES6, I really like to do stuff like this:

const names = animals.map(({name, species}) => `${name} is a ${species}`);

Keep up the great work!

Collapse
 
tifflabs profile image
tiff

Template literals are the sh*t! Yeah. I should have done that but didn't think to use it there. Thanks for the suggestion!

Collapse
 
jsdbroughton profile image
jonathon

If you find yourself using .map().filter or .filter().map() a lot then invest some time learning .reduce()

Collapse
 
tifflabs profile image
tiff

Definitely. I was just posting each function in different posts. This is my next one!

Collapse
 
ben profile image
Ben Halpern

Another great post, Tiffany.

Collapse
 
tifflabs profile image
tiff

Thanks Ben!

Collapse
 
itsjzt profile image
Saurabh Sharma

here is a good video on using map Map - Part 2 of Functional Programming in JavaScript

One for filter too Filter

Collapse
 
angelitodiaz1 profile image
Angel Diaz

Thanks Tiffany. Useful.