Created
November 20, 2015 06:17
-
-
Save minsooshin/5f88206de281cb808148 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin '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: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function where(collection, source) { | |
var arr = []; | |
function check(val) { | |
var obj = {}; | |
for (var key in source) { | |
obj = val[key] === source[key] ? val : null; | |
} | |
if (obj) { | |
arr.push(obj); | |
} | |
} | |
collection.filter(check); | |
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