My solution to "Wherefore art thou" does not pass

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);
  .filter(obj => testKeys
      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

Challenge: Wherefore art thou

Link to the challenge:

When I run this code:

console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }))

The response I get is:

[ [ { first: 'Tybalt', last: 'Capulet' } ] ]

The expected response is:

[{ first: "Tybalt", last: "Capulet" }]

Those are not the same. The double/single quotes don’t matter - you have a bigger issue.

1 Like

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.

Why push the results of the filter into arr instead of just using the returned array from filter?

well I had to do that:

return collection
.filter(obj => testKeys
key => obj.hasOwnProperty(key) && obj[key] === source[key]

how ever originally the exercise had an strict area to write in and

return arr;

was not intended to be edited if I recall correct…

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.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.