var robots = [ {color:'blue' , orient:'back'}, { color:'purple' , orient:'front'}, { color:'red' , orient:'front'}, {color:'green' , orient:'front'}, { color:'blue' , orient:'front'}, {color:'blue' , orient:'back'}, { color:'purple' , orient:'front'}, { color:'red' , orient:'front'}, {color:'green' , orient:'front'}, { color:'blue' , orient:'front'} ]
Check out the array above. What if you want to only return the green robots? Sure, you could use an 'if' statement within a map function. That would not be the functional programming approach. Functional programming focuses on making code more readable for any viewer. Although this example will be small, it becomes a much bigger deal with a massive code base that many people use.
var greenBots= [...]
This is what we want to end with.
How might we do this with higher order functions?
We need to use a .filter() function to first sort out the green robots. Then we will add the results to the greenRobots array.
var greenBots = robots.filter().map();
We can chain a map method to our filter method.
Docs