Skip to content

Instantly share code, notes, and snippets.

@dtzitz
Created June 6, 2016 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtzitz/cceafb41e9ac9a23e92da2fef850f44c to your computer and use it in GitHub Desktop.
Save dtzitz/cceafb41e9ac9a23e92da2fef850f44c to your computer and use it in GitHub Desktop.
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