Wherefore art thou Challenge / (code help)

Wherefore art thou Challenge / (code help)
0.0 0

#1

Tell us what’s happening:
I’m only partially passing this challenge and would like pointers/guidance as what I can do to fix this wholly so it passes.

function whatIsInAName(collection, source) {
  
  var matchedObjectProps = []; // an array to capture objects that match `source` key/value pairs
  
  collection.forEach(function(objectArgument) {
    var objectProps = Object.keys(objectArgument); // an array of object keys from `objectArgument`
    
    for (var key in source) { // for each property defined in the `source` object
      objectProps.forEach(function(prop) {
        if (objectArgument.hasOwnProperty(prop) && objectArgument[prop] === source[key]) {
          matchedObjectProps.push(objectArgument);
        }
      });
    }
  });
  return matchedObjectProps;
}
                         

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

Link to the challenge:


#2

Your solution is adding more collection objects than there are object in the object collection. You just got lucky on the first two tests.