Summary
In this chapter, we started working with HOFs to show a more declarative way of working with shorter, more expressive code. We went over several operations: we used reduce()
and reduceRight()
to get a single result from an array, map()
to apply a function to each element of an array, forEach()
to simplify looping, flat()
and flatMap()
to work with arrays of arrays, filter()
to pick elements from an array, find()
and findIndex()
to search in the arrays, and every()
and some()
(plus a made-up none()
) to verify general logic conditions. We then considered some unexpected situations when you deal with async
functions, and we wrote special functions for those cases. Finally, we showed how to do parallel work functionally for extra performance.
In Chapter 6, Producing Functions, we will continue working with HOFs, but we will write our own ones to gain more expressive power for our coding.