I am lost with what is the problem here
here is the problem, the code bellow seems to give desired outcomes for all tests (in my dev tools console), but it does not pass any of them…
This is not the first time I am messing code just by enough to brick tests.
Your observations would be appreciated.
**Your code so far**
function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line
let testKeys = Object.keys(source);
arr.push(collection
.filter(obj => testKeys
.every(
key => obj.hasOwnProperty(key) && obj[key] === source[key]
)
)
)
// Only change code above this line
return arr;
}
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/101.0.4951.54 Safari/537.36
Thank you again,
chose to return the filtered collection instead of pushing it into an array.
Goes a bit against the rules because I ended up editing code bellow the line I was allowed to…
I did try to concat() filtered results into arr, but no bueno.
Right, in theory, just putting that return in the middle there, it will ignore the one at the end so that “works” well enough. Personally I find the way they organize that a little annoying - at this point I think they could take the training wheels off. Personally, I would do what you did, just return it immediately. There are ways to do it within the restrictions that they have here: declare the array, work on it in the middle, then return the array at the end. I find that unnecessarily verbose, but it is doable. Whether or not you need to figure that out is up to you.