Drop it [one test case is bugging]

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:

Hint: 0 is falsy.

1 Like

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

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

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: