Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active August 12, 2018 01:26
Show Gist options
  • Save crshmk/5dd0c90165c6afb194b376660fe6ded7 to your computer and use it in GitHub Desktop.
Save crshmk/5dd0c90165c6afb194b376660fe6ded7 to your computer and use it in GitHub Desktop.
Apply array of filters
/**
* @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