[Solved]Can only pass 3 of 4 tests in 'Wherefore art thou'. What am I missing?

Tell us what’s happening:
I can only pass 3 of 4 tests

Your code so far

function whatIsInAName(collection, source) {
  var sourceKeys = Object.keys(source);
  var result = [];
  var noOfMatchingProperties = 0;
	
  collection.forEach(function(element, index){
    noOfMatchingProperties = 0;
		
    for(var i = 0; i < sourceKeys.length; i++){
	  if(element.hasOwnProperty(sourceKeys[i])){
	    noOfMatchingProperties++;
	  }
	}
    
	if(noOfMatchingProperties === sourceKeys.length){
	  result.push(element);
	}
    
  });
	
  return result;
}

Your browser information:
Chrome/65.0.3325.181
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/wherefore-art-thou

Hello,

I assume your code is failing on test one, right? This is because you’re checking if the property exists in both the collection and the source, but you also want to know its content.

Have a second look at that and probably it won’t fail.

Happy coding!

1 Like