January 2020
Intermediate to advanced
470 pages
11h 13m
English
The last functions we are going to consider greatly simplify going through arrays to test for conditions. These functions are as follows:
For example, we could easily check our hypothesis about all the countries having negative coordinates:
markers.every(v => v.lat < 0 && v.lon < 0); // falsemarkers.some(v => v.lat < 0 && v.lon < 0); // true
If we want to find equivalents to these two functions in terms of reduce(), the two alternatives show nice symmetry:
arr.every(fn);// arr.reduce((x, y) => x && fn(y), true);arr.some(fn);