Skip to content

Instantly share code, notes, and snippets.

@ArielLeslie
Created October 6, 2015 17:34
Show Gist options
  • Save ArielLeslie/6076f279baa35a672ba7 to your computer and use it in GitHub Desktop.
Save ArielLeslie/6076f279baa35a672ba7 to your computer and use it in GitHub Desktop.
Where Art Thou
function where(collection, source) {
var arr = [];
// What's in a name?
src_keys = Object.keys(source);
arr = collection.filter(function(i){
for(j = 0; j < src_keys.length; j++){
if(!i.hasOwnProperty(src_keys[j]) || i[src_keys[j]] !== source[src_keys[j]]){
return false;
}
}
return true;
});
// A rose by any other name
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment