Wherefore art thou can't seem to pass test cases

Wherefore art thou can't seem to pass test cases
0

#1

Tell us what’s happening:
What am I missing here? My solution seems to return the correct answer but I am not passing any of the test cases.

Your code so far


function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  let sourceKeys = Object.keys(source);
  arr.push(collection.filter(function (obj) {
    return sourceKeys.every(function (key) {
      return obj.hasOwnProperty(key) && obj[key] === source[key];
    });
  }));
  // Only change code above this line
  return arr;
}

console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
console.log(whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3}));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou


#2

Array.prototype.filter returns an Array, so you are nesting an Array within another Array.
Try returning the result of collection.filter instead.


#3

Thank you so much. I wasn’t thinking when I was pushing an array into the array.