Drop it [one test case is bugging]

Drop it [one test case is bugging]
0

#1

Tell us what’s happening:
The solution passes all the test cases except for this one provided !!
the [0, 1, 0, 1] array with its condition returns [1, 1]
I’ve see the hints provided by FCC and they were using Array.shift(), but I couldn’t figure out why this issue is happening for this case.

I know it’s not a filtering problem, but since it passed the last test case (the [1, 2, 3, 9, 2] with its condition), I see it should pass the second test case too!!

I need to understand why it is bugging, ughhh :upside_down_face:
Your code so far


function dropElements(arr, func) {
  // Drop them elements.
  let flag = true
  return arr.filter((elm) => {
    if (func(elm))
      flag = false
    if (!flag)
      return elm
  });
}
console.log(dropElements([0, 1, 0, 1], function(n) {return n === 1;}))


Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0.

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


#2

Hint: 0 is falsy.


#3

didn’t see that coming :joy:
does that mean there is no way to return 0 in the filter function?


#4

Look carefully at how filter() works and what its return value is.


#5

yeah absolutely. Well, I’ve got it done using toString() , I don’t know how efficient is this, but I’ll try to find a better solution.
Any ways Thanks bud :grinning: