For loop inside a filter

Tell us what’s happening:

I’m looking at the basic code solution, but don’t really understand why how the for loop inside the filter function works.

After it loops through all the items in srcKeys, it will return multiple True or False, but i thought the filter function can only take one True or False. Please explain what happens here. Thanks!

Your code so far


function whatIsInAName(collection, source) {
  // "What's in a name? that which we call a rose
  // By any other name would smell as sweet.”
  // -- by William Shakespeare, Romeo and Juliet
  var srcKeys = Object.keys(source);

  // filter the collection
  return collection.filter(function (obj) {
    for(var i = 0; i < srcKeys.length; i++) {
      if(!obj.hasOwnProperty(srcKeys[i]) || obj[srcKeys[i]] !== source[srcKeys[i]]) {
        return false;
      }
    }
    return true;
  });
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36.

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

Does it mean for each element in collection, the filter function will run through the whole for loop? In that case, each element in collection will get multiple True and false since some
elements in srcKeys will meet the condition and some won’t. How does the filter decide whether to keep an element or not?