Skip to content

Instantly share code, notes, and snippets.

@delta48
Created January 22, 2022 02:32
Show Gist options
  • Select an option

  • Save delta48/e8ef5cfab6468dd2a22d6b8dd85912eb to your computer and use it in GitHub Desktop.

Select an option

Save delta48/e8ef5cfab6468dd2a22d6b8dd85912eb to your computer and use it in GitHub Desktop.
/*
solution for
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou
*/
function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line
arr.push(...collection.filter(el => Object.keys(source).every(key => (key in el && el[key] === source[key]))))
// Only change code above this line
return arr;
}
whatIsInAName([{ 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