Skip to content

Instantly share code, notes, and snippets.

@Willovent
Last active February 25, 2017 18:32
Show Gist options
  • Save Willovent/e797f68562822ca59023 to your computer and use it in GitHub Desktop.
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}]
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