Wherefore art thou solution returning [ ]

Tell us what’s happening:
why my code is returnung

Your code so far

function whatIsInAName(collection, source) {
var arr = collection.filter(function(item){
for(var i in source){
if (source[i] != item[i]){
return false;

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


Your browser information:

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

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

Try adding return true after the for loop completes. I’m not sure if that’ll handle all of the tests, but it should get things back on track.

Tell us what’s happening:

Your code so far

function whatIsInAName(collection, source) {
var arr = collection.filter(function(item){
for(var i in source){
if (source[i] != item[i]){
return false;

}
}
});
return arr;
}

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

Your browser information:

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

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

@camperextraordinaire @sa-mm solution is not working .

function whatIsInAName(collection, source) {
  var arr = collection.filter(function(item){
    for(var i in source){
      if (source[i] != item[i]){
return true;

    }
  }
});
return arr;
}

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


@sa-mm and @camperextraordinaire thanks for help its working now .

@camperextraordinaire its working thanks for help.

Hello,
In the code below, I try to create a pure function, but it doesn’t work.
I get an Error: false is not a function.
Is there anything I can do to fix it.
Thank you.

Spoiler
  function whatIsInAName(collection, source) {
      // What's in a name?
      var arr = [];

      // a pure function
     // that checks the matching proprties/values
      let getProperties = function(arr, source) {

        for (var i = 0; i < arr.length; i++) {
          for (let prop in source) {
            console.log('arr', arr[i][prop]);
            console.log('source ', source[prop]);
            if (arr[i][prop] !== source[prop]) {
              return false
            }
          }
          return true
        }
      }
     
      arr = collection.filter(getProperties(collection, source));
      return arr;
    }

    console.log(whatIsInAName([{
      "apple": 1,
      "bat": 2
    }, {
      "bat": 2
    }, {
      "apple": 1,
      "bat": 2,
      "cookie": 2
    }], {
      "bat": 2,
      "apple": 1
    }));

That is not how you pass a callback function to filter, you are running getProperties, not passing it as a callback.

// Check the console to see what is getting passed to the callback
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];

  // a pure function
  // that checks the matching proprties/values
  let getProperties = function (ele, index, array) {
    console.log(ele, index, array);
  }

  arr = collection.filter(getProperties);
  return arr;
}
Spoiler
// Here is version that seems to work
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];

  // a pure function
  // that checks the matching proprties/values
  let getProperties = function (ele) {
    for (const key in source) {
      if (source[key] != ele[key]) {
        return false;
      }
    }
    return true;
  }

  arr = collection.filter(getProperties);
  return arr;
}

Why do you add true after the for loop ends instead of say putting in an else statement after the if statement? Aren’t we resetting the value to true for the filter function for every property when the true returns after the for loop?