Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Checking negatives - none

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 earlier saw -- 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 in Chapter 8, Connecting Functions - Pipelining and Composition.

Array.prototype.none = function(fn) { return ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content