Created
October 26, 2018 02:41
-
-
Save jossmac/b26441076a05127efdb4ecacd0e50f11 to your computer and use it in GitHub Desktop.
Negation function for less verbose code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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