Hello, I am having a hard time solving Wherefore art thou challenge, here’s my code so far :
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
console.log(JSON.stringify(
collection.filter((obj) =>{ return obj.filter
(function(property) {if(obj[property] === source[property]){
return obj}}) } )))
// Only change code above this line
return arr;
}
console.log(JSON.stringify(whatIsInAName([{ first: “Romeo”, last: “Montague” }, { first: “Mercutio”, last: null }, { first: “Tybalt”, last: “Capulet” }], { last: “Capulet” })));;`
So the idea so far is that I should use array.prototype.filter method for this challenge and the problem I had with it is that I couldn’t figure out how to pass property of an object as a variable without hard-coding it. So I thought maybe I could go a layer deeper and iterate through the properties instead of just objects, so that’s what the second .filter function is for. However I get an error obj.filter is not a function. How can I avoid that and should I be using filter here at all?
Link to the challenge : https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou/
Edit : Found out that using [obj].filter solves the error but I still can’t solve the challenge