Wherefore art thou solution returning [ ]

Wherefore art thou solution returning [ ]
0

#1

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:


#2

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.


#3

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:


#4

@sa-mm told you exactly how to fix your solution. It would make it easier for you and everyone else reading your code if you would indent your code.


#5

@randelldawson @sa-mm solution is not working .


#6

Post your latest code, so we can see if how you implemented it.


#7
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" });



#8

Your original solution was 99% correct. All you had to do was add return true after the for loop ends. Why would you want to add return true inside the if block of code? That will make your filter function keep collection items not in source.


#9

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


#10

@randelldawson its working thanks for help.