Created
April 18, 2018 04:20
-
-
Save AIndoria/f32f95c3c79c4b5563d7a737cb65e691 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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