Skip to content

Instantly share code, notes, and snippets.

@MrRhodes
Created January 8, 2015 21:23
Show Gist options
  • Save MrRhodes/5f3d60c2c26148b514aa to your computer and use it in GitHub Desktop.
Save MrRhodes/5f3d60c2c26148b514aa to your computer and use it in GitHub Desktop.
Array filter chaining for a basic "rules" implementation.... (not run this code, so might have errors, but you get the idea)
var items = [
...
];
var satisfied = items
.filter(condition1(5))
.filter(condition2('camel'))
.filter(condition3)
function condition1(something) {
return function(item) {
return item.value > something;
}
}
function condition2(animal) {
return function(item) {
return item.animal === animal;
}
}
function condition3(item) {
return item.alive === true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment