-
-
Save omnidan/3432a5dc51e876e2803cc59998562c09 to your computer and use it in GitHub Desktop.
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
const arg1 = (arg) => arg !== 1 | |
const arg2 = (arg) => arg !== 2 | |
function combineFilters (filters) { | |
return filters.reduce((prev, curr) => | |
(arg) => prev(arg) && curr(arg) | |
, () => true) | |
} | |
console.log(combineFilters([arg2, arg1, arg1])(1)); // false | |
console.log(combineFilters([arg2, arg1, arg1])(2)); // false | |
console.log(combineFilters([arg2, arg1, arg1])(3)); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also skip having people adding the array, by using the spread operator to parse the arguments.