Other higher-order functions
Let's end this chapter by considering other sundry functions that provide results such as new finders, decoupling method from objects, and more.
Turning operations into functions
We have already seen several cases in which we needed to write a function just to add or multiply a pair of numbers. For example, in the Summing an array section of Chapter 5, Programming Declaratively - A Better Style, we had to write code equivalent to the following:
const mySum = myArray.reduce((x, y) => x + y, 0);
In the same chapter, in the section Working with ranges, to calculate a factorial, we then needed this:
const factorialByRange = n => range(1, n + 1).reduce((x, y) => x * y, 1);
It would have been easier if we could just turn a binary operator into a function that calculates the same result. The preceding two examples could have been written more succinctly, shown as follows:
const mySum = myArray.reduce(binaryOp("+"), 0);
const factorialByRange = n => range(1, n...