Bug in the third condition of challenge Wherefore art thou?

Tell us what’s happening:

This program is returning something that doesn’t accomplished the third condition of this challenge, whereas, it seems like it does.

Your code so far


function whatIsInAName(collection, source) {
 var arr = [];
 // Only change code below this line

arr = collection.filter(function (pair){
   if (pair.apple == source.apple){
     return true
   }
 })

 // Only change code above this line
 return arr
}
whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }, { "bat":2 }], { "apple": 1, "bat": 2 })// --> [ { apple: 1, bat: 2 },  { apple: 1 },  { apple: 1, bat: 2, cookie: 2 } ]

Your browser information:

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

Challenge: Wherefore art thou

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

The test says:

whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 }) should return [{ "apple": 1, "bat": 2, "cookie": 2 }] .

But when I run your code with :

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

I get back:

[
  {
    apple: 1,
    bat: 2
  },
  {
    apple: 1
  },
  {
    apple: 1,
    bat: 2,
    cookie: 2
  }
]

which is not the correct answer. The second element should not be there because it does not contain both of the conditions provided: { "apple": 1, "bat": 2 }.

That’s right. Thats what I’m saying! (when you run this code --which is wrong in terms of the challenge-- the third condition is checked.

Are you trying to find a bug or solve the challenge? :slight_smile:

It doesn’t mean it’s wrong against particular test coincidentally

Of course: the challenge. And I’m really really stuck here… and maybe I’m that bored that I just commented about the “coincidental” bug :sweat_smile: