Created
January 8, 2015 21:23
-
-
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)
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
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