Wherefore art thou - I'm stuck!

Tell us what’s happening:
I’m stuck. I don’t know what else to try. How to check if an object from collection has the same value as source? Should i even check that or something else? please help.

Your code so far

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  var keys = Object.keys(source);
  var val = Object.values(source);
  var dr;
  // Only change code below this line
  arr = collection.filter(function(o){
    for(var i=0; i < keys.length; i++)
      return o.hasOwnProperty(keys) && Object.is(o[keys[i]],val[i]);
  });
 
 /* for(var i=0; i < collection.length; i++){
    for(var j=0; j < val.length; j++){
      if(collection[i].hasOwnProperty(keys[i]) || Object.is(collection[i][keys[j]],val[j])){
        arr.push(collection[i]);    
      }  
    }
  }*/
  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36```.

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

ok , so i did this:

return o.hasOwnProperty(keys[i]) && Object.is(o[keys[i]],val[i]);

first and second tests are good, 3rd and fourth still dont return the right value.

I finally did it somehow, but im not sure if its right. Thank you mr. rmdawson17 for your time.
Now i can go to sleep :smiley:

function whatIsInAName(collection, source) {
  var arr = [];
  var keys = Object.keys(source);
  var val = Object.values(source);
  arr = collection.filter(function(o){
    for(var i=0; i < keys.length; i++)
      return o.hasOwnProperty(keys[i]) && Object.is(o[keys[i]],val[i]) && Object.is(o[keys[i+1]],val[i+1]);
  });
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });

There are multiple ways to do this, an easy one to follow is to loop over the keys until you find the one that does not match, and return false at that point, if your code gets through the loop and all the key/value pairs match then you return true. This concept is called early return, same idea could be used by having a flag variable before the loop that defaults to true, and is set to false if any of the key/pairs don’t match. After the loop you can return that flag variable for your filter. A sample of early return can be found in mdn in the section interrupt a function.

Another way is a handy function from the Array object called every, with this function you can test all the elements of an array, and if all the tests are true, it returns true and if any of the tests is false it returns false. An easy way to replace the loop completely with a call to every. Check it out in mdn.

Hope those help you to get a more complete solution

thank you guys. i knew my solution is not good.