January 2020
Intermediate to advanced
470 pages
11h 13m
English
Let's end this section by creating an extension of the find() method. Suppose we want to find the optimum value—let's suppose it's the maximum—of an array of numbers. We could make do with this:
const findOptimum = arr => Math.max(...arr);const myArray = [22, 9, 60, 12, 4, 56];findOptimum(myArray); // 60
Now, is this sufficiently general? There are at least a pair of problems with this approach. First, are you sure that the optimum of a set will always be the maximum? If you were considering several mortgages, the one with the lowest interest rate could be the best, couldn't it? That is, assuming that always wanting the maximum of a set is too constrictive.
Read now
Unlock full access