Skip to content

Instantly share code, notes, and snippets.

@jossmac
Created October 26, 2018 02:41
Show Gist options
  • Save jossmac/b26441076a05127efdb4ecacd0e50f11 to your computer and use it in GitHub Desktop.
Save jossmac/b26441076a05127efdb4ecacd0e50f11 to your computer and use it in GitHub Desktop.
Negation function for less verbose code
function not(predicate) {
return function negate(...args) {
return !predicate(...args);
}
}
// Usage
// ==============================
function longEnough(str) {
return str.length > 10;
}
const tooShort = not(longEnough);
console.log(longEnough('Does this work?')); // true
console.log(tooShort('Does this work?')); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment