-
-
Save dtzitz/cceafb41e9ac9a23e92da2fef850f44c to your computer and use it in GitHub Desktop.
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 whereAreYou(collection, source) { | |
// What's in a name? | |
var arr = []; | |
// Only change code below this line | |
var sourceKeys = Object.keys(source); | |
for (var i=0;i<collection.length;i++){ | |
for(var l=0;l<sourceKeys.length;l++){ | |
var prop = sourceKeys[l]; | |
if(collection[i].hasOwnProperty(sourceKeys[l]) && collection[i][prop] === source[prop]){ | |
arr.push(collection[i]); | |
} | |
} | |
} | |
//console.log(arr); | |
// Only change code above this line | |
return arr; | |
} | |
whereAreYou([{ 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