Negate predicate

JavaScript, Function · Sep 15, 2020

Negates a predicate function.

  • Take a predicate function and apply the not operator (!) to it with its arguments.
const negate = func => (...args) => !func(...args);

[1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ]

More like this

  • Check property

    Creates a function that will invoke a predicate function for the specified property on a given object.

    JavaScript, Function · Nov 1, 2020

  • Where and how can I use memoization in JavaScript?

    Learn different ways to memoize function calls in JavaScript as well as when to use memoization to get the best performance results.

    JavaScript, Function · Nov 7, 2021

  • Boolean traps and how to avoid them

    Boolean traps can cause readability and maintainability issues in your code. Learn what they are, how to spot and fix them in this article.

    JavaScript, Function · Jul 11, 2021