Tell us what’s happening:
So I’m struggling on this pretty hard. What I have passes some of the checks but doesn’t for the others.Originally I wanted to use filter but trying to implement it I realized I has no idea what exactly I’d set to filter. Anyway I think it might have something to do with the other checks including arguments with more than one property. Thinking along those lines I’m still not sure what direction to do. I was thinking maybe storing the source properties in another array and checking them against the collection? I’m just confused and kinda of struggling to find a direction to go. Advice is appreciated.
Your code so far
function whatIsInAName(collection, source) {
const arrForName = [];
const sourceProp = Object.keys(source);
console.log(source[sourceProp]);
for (const obj in collection) {
for(const objProp in collection[obj]) {
if (collection[obj].hasOwnProperty(sourceProp)&&collection[obj][objProp] === source[sourceProp]){
arrForName.push(collection[obj]);
}
}
}
console.log(arrForName);
return arrForName;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
Challenge: Intermediate Algorithm Scripting - Wherefore art thou
Link to the challenge: