10/7/2016 ~ 3 min read

Warming Up With Array.filter


➜ ~ node

var myArray = [ … {id:1},{id:2},{id:3},{id:4},{id:5},{id:6},{id:7},{id:8},{id:9},{id:0}] undefined myArray [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }, { id: 9 }, { id: 0 } ] function isGreaterThan5(obj) { … if(obj.id && obj.id > 5) { … return true; … } … else { … return false; … } … } undefined var above5 = myArray.filter(is isFinite isNaN

isGreaterThan5

isPrototypeOf

var above5 = myArray.filter(isGreaterThan5); undefined above5 [ { id: 6 }, { id: 7 }, { id: 8 }, { id: 9 } ]

It’s like finding a well used but oddly shaped hammer the previous owner left in the back of a utility closet. The first time you see it you think, ‘Hmm I wonder what that hammer is useful for.’ Then you clean out the closet and put the hammer with your other tools. After a while it collects dust and you clean it off on a cold early Saturday morning. At this point you look for a problem to solve with it. The internets and other digital tubes are very useful in this regard these days but you probably don’t find much, you barely know what it is you are searching for. You may find out the name of it. You may learn about its history and the evolution into what you hold in your hands today. Then you put it back in the toolbox, make breakfast and talk to your family. After breakfast you do chores and mull on what you learned about the rusty old hammer. Because if you don’t get anything done for yourself on the weekends unless its before 7AM you don’t get to pick up the hammer again until Monday morning when you start the weeks work. But its been on your mind and you look for opportunities to use that new hammer. There are opportunities everywhere. All of your tasks look like nails adapted to be hit by the hammer. So hammer away you do. And by lunch when you look back at the long line of nails in different materials you some that look perfectly pounded but don’t do anything useful and others, bent and crooked that seem to, just barely, keep everything together. Then as you look back, there is the One. The One that is perfectly pounded into several different materials and it not only holds them together but it pulls them together in an effortless way that just makes sense. Taking that One Experience away, you reflect on what you were thinking when you worked on it. If you can remember anything at all, it’s more of a feeling: “Ok, lets try it this way and then move on to the next task.” This Way ends up being pretty useful and sometimes elegant. This Way is something you can take forward as you attack your forest of nails. screen-shot-2016-10-07-at-7-39-39-am


Headshot of Matthew Hippely

Hi, I’m Matthew. I live in Ventura County, and spend my time thinking about systems, software, and how things evolve over time.

You can find me on GitHub, LinkedIn, or read more about me here.