January 2020
Intermediate to advanced
470 pages
11h 13m
English
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 Working with ranges section of Chapter 5, Programming Declaratively – A Better Style, to calculate a factorial, we wrote 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, as ...
Read now
Unlock full access