January 2020
Intermediate to advanced
470 pages
11h 13m
English
If you wanted, you could also define none() as the complement of every(). This new function would be true only if none of the elements of the array satisfied the given predicate. The simplest way of coding this would be by noting that if no elements satisfy the condition, then all elements satisfy the negation of the condition:
const none = (arr, fn) => arr.every(v => !fn(v));
If you want, you can turn it into a method by modifying the array prototype, as we saw earlier; it's still a bad practice, but it's what we have until we start looking into better methods for composing and chaining functions, as we will see in Chapter 8, Connecting Functions – Pipelining and Composition:
Array.prototype.none = function(fn) ...
Read now
Unlock full access