Most of what I've read about functional programming is big on philosophy and short on pragmatism. This series of posts is my attempt to learn some of the basics of functional programming and to write about them in a way that jerks like me can understand.
filteris a higher-order function that processes a data structure (typically a list) in some order to produce a new data structure containing exactly those elements of the original data structure for which a given predicate returns the boolean value true.
What I Think That Means
We're going to take an array and run a function on each element that will return true or false to determine whether that element should be in a new array. Like our new friend
map this sounds a lot like a for-in loop in disguise.
The Old Way
The Functional Way
map, I maybe see what they're going for here. I still think the more verbose for-in is an easier read but at least the name
filter makes it pretty obvious what's happening.