Tell us what’s happening:
I was making some progress (this passes the first 3 tests), but I have been at a standstill now for hours. I tried to comment in my thought process throughout. I believe my problem is with my callback function for the filter. specifically, my callback function is not vetting properly. Even more specifically, after some testing, I think it has something to do with the if
statement in my for..in
loop. I’m gonna take a break from this one, the word “source” is staring to look weird to me haha. I’m considering scrapping the whole thing and trying another method. End vent - actual questions:
-
Is the method I am trying here sound? Should I just scrap it an try anew?
-
If my methodology is sound, is there some simple mistake I am making in my callback function?
Thanks
Your code so far
function whatIsInAName(collection, source) {
//callback function for filter
function propCheck(collectionObj) {
for(let sourceProperty in source) { //check each property in 'source'
if (collectionObj.hasOwnProperty(sourceProperty) &&
(source[sourceProperty] === collectionObj[sourceProperty])) {
return true; // filter accepts IF all props/values (from source) are in collection
} else {
return false; //otherwise filter will reject
}
}
}
// the filter will create a shallow copy, 'filteredNames'
let filteredNames = [];
return filteredNames = collection.filter(propCheck);
// return the shallow copy
}
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Wherefore art thou
Link to the challenge: