Last active
February 25, 2017 18:32
-
-
Save Willovent/e797f68562822ca59023 to your computer and use it in GitHub Desktop.
Array whereusage : [{name : "William", age : 24}, {name : "Bertrand", age : 47}].where({age : 24}); => return : [{name : "William", age : 24}]
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 where = function(data, predicate) { | |
var newArray = []; | |
data.forEach(function(e) { | |
var add = true; | |
for (pred in predicate) { | |
if (predicate[pred] != e[pred]) { | |
add = false; | |
break; | |
} | |
} | |
if (add) | |
newArray.push(e); | |
}); | |
return newArray; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment