Tell us what’s happening:
My current try works when matching objects for 1 common element (like the second case in this challenge). But comparing, for example, [{a : 1, b : 2, c : 3}]
with [{a : 1, c : 3}]
throws an empty array, while a want to return the first array (because it has the elements of the second array). I’ve been reading hasOwnProperty and Object.keys in MDN…
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
arr = collection.slice().filter(object => object.hasOwnProperty(Object.keys(source)))
// Only change code above this line
return arr
}
console.log(whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 }));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.72
.
Challenge: Wherefore art thou
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou