Created
December 10, 2015 22:46
-
-
Save anonymous/de077f0a3b41243383af to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Where art thou
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
// 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) | |
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