Last active
August 12, 2018 01:26
-
-
Save crshmk/5dd0c90165c6afb194b376660fe6ded7 to your computer and use it in GitHub Desktop.
Apply array of filters
This file contains hidden or 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
/** | |
* @param array of unary functions | |
* @param array of any | |
* @return array of any | |
*/ | |
filterMany = (f, d) => | |
f.length < 2 ? d.filter(f[0]) : filterMany(f, d.filter(f.shift())) | |
let xs = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; | |
let gt10 = x => x > 10; | |
let isEven = x => x % 2 === 0; | |
filterMany([gt10, isEven], xs); | |
// -> [ 12, 14, 16, 18, 20 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment