Sometimes you just gotta map a b***h

If you’re like me, you like to get to the point whether in life or in programming. No beating around the bush needed, but sometimes people like to beat that bush until there ain’t no leaves left…

Get on with it already…

I had enough of these people, so I set out on a Journey (thanks Jeff Webb). A journey to find a way around these people. After much searching I had an epiphany, I said to myself “if I need to find my way around, I’m gonna need a Map!”

Thanks Dora!

You know what’s great about maps? They work in real life and in programmer land! Need to find your way around traffic? Use MapQuest! Hate writing boring long for loops? Boom, throw some map on it and you're good to go…Let me show you.

Lame ‘for’ loop

for (let i = 0; i < path.length; i++) {
if (path[i] === ‘bush’) { Avoid }
else {Walk through}
}

So much writing…. man I think my fingers are gonna fall off

Now, behold the power of the Map

path.map( (stops) => {
if (stops === ‘bush’) { Avoid }
else {Walk through}
})
74 > 63????

Both of the snippets of code will run through the entire path array, but map only takes 63 characters, while the traditional ‘for’ loop took a whooping 74 characters…and if my 5 years as a high school math teacher has taught me anything, its that 74 is more than 63.

So remember kids, next time you go write a for loop to run through an entire array, save your fingers from early onset arthritis, and use a map! You don't want to end up like this guy!

Chris, I told you to stop doing that so much!
Like what you read? Give Michael Solone a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.