Skip to content

Instantly share code, notes, and snippets.

@AIndoria
Created April 18, 2018 04:20
Show Gist options
  • Select an option

  • Save AIndoria/f32f95c3c79c4b5563d7a737cb65e691 to your computer and use it in GitHub Desktop.

Select an option

Save AIndoria/f32f95c3c79c4b5563d7a737cb65e691 to your computer and use it in GitHub Desktop.
function whatIsInAName(collection, source) {
// "What's in a name? that which we call a rose
// By any other name would smell as sweet.”
// -- by William Shakespeare, Romeo and Juliet
var sourceKeys = Object.keys(source);
return collection.filter(function(collectionElement){
return sourceKeys.every(function(sourceElem){
return collectionElement.hasOwnProperty(sourceElem) && collectionElement[sourceElem]==source[sourceElem];
});
});
}
// test here
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment