Skip to content

Instantly share code, notes, and snippets.

@minsooshin
Created November 20, 2015 06:17
Show Gist options
  • Save minsooshin/5f88206de281cb808148 to your computer and use it in GitHub Desktop.
Save minsooshin/5f88206de281cb808148 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Where art thou
// 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