Skip to content

Instantly share code, notes, and snippets.

@vmlinz
Created September 15, 2015 04:47
Show Gist options
  • Save vmlinz/cf5a1421ea4c087005fc to your computer and use it in GitHub Desktop.
Save vmlinz/cf5a1421ea4c087005fc to your computer and use it in GitHub Desktop.
freecodecamp_where.js
function where(collection, source) {
return collection.filter(function (v) {
for (var i in source) {
if (!(v.hasOwnProperty(i) && (v[i] === source[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