Created
July 27, 2015 03:44
-
-
Save alexandrebvd/813c3b58811e2eea681c to your computer and use it in GitHub Desktop.
16.Bonfire: Where art thou
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
function where(collection, source) { | |
var arr = []; | |
var findKeys = Object.keys(source); | |
for (var i = 0; i < collection.length; i++) { | |
var currentObj = collection[i]; | |
for (var j = 0; j < findKeys.length; j++) { | |
var key = findKeys[j]; | |
if (currentObj.hasOwnProperty(key) && currentObj[key] === source[key]) { | |
arr.push(currentObj); | |
} | |
} | |
} | |
return arr; | |
} | |
where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment