Implement a Matching Object Filter - Implement a Matching Object Filter

Tell us what’s happening:

I can’t seem to pass test number five.. all others are correct

Your code so far

function whatIsInAName (arr, src){


let filterRes = arr.filter(obj => Object.keys(obj).join("").includes(Object.keys(src).join("")) && Object.values(obj).join("").includes(Object.values(src).join(""))) 

return filterRes 

}

 
console.log(whatIsInAName ([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 }))   

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 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0

Challenge Information:

Implement a Matching Object Filter - Implement a Matching Object Filter

Have you looked at the values that are compared during failing test?

not sure what you mean.. test number 5 returns an empty array… my code doesn’t recognize the keys for that particular test for some reason..only the values

let filterRes = arr.filter(obj => Object.keys(obj).join("").includes(Object.keys(src).join("")) && Object.values(obj).join("").includes(Object.values(src).join(""))) 

This long line of code compares 2 expressions which evaluate into values when the code is run. When the code is running, you’d like to see exactly what two values are being compared.

Can you use console.log() within your filter function to send those values to the log so you can see them?

when i run console.log on the above code it return false false false… but when i run console.log with the key check removed it returns true false true

What do those values represent? Maybe you can use something more descriptive like:

console.log("First value is ", Object.keys(obj)
                                      .join("")
                                      .includes(Object.keys(src)
                                          .join(""))
console.log("Second value is ", Object.values(obj).join("").includes(Object.values(src).join("")))

And are the results what you expect?

the values for the key check is false false false

values for the value check is true false true

Ok does that tell you anything?

Maybe log the actual keys that are being compared? and the values?

Break those lines into smaller pieces and log until it’s clear exactly what’s happening