Skip to content

Instantly share code, notes, and snippets.

@TylerL-uxai
Forked from anonymous/bonfire-where-art-thou.js
Last active December 10, 2015 22:46
Show Gist options
  • Save TylerL-uxai/aa23d476ad95ea860e60 to your computer and use it in GitHub Desktop.
Save TylerL-uxai/aa23d476ad95ea860e60 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Where art thou
// Bonfire: Where art thou
// Author: @tylerl-uxai
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou
// Learn to Code at Free Code Camp (www.freecodecamp.com)
// Rewritten myself with help from https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Bonfire-Where-art-thou
function where(collection, source) {
// speed test
var keys = Object.keys( source ); // returns the keys to the variable
return collection.filter(function(propertiesForEachKey){
for (var i = 0; i< keys.length; i++){
if(!propertiesForEachKey[keys[i]] || source[keys[i]] !== propertiesForEachKey[keys[i]]){
return false;
}
}
return true;
});
}
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