Drop it - question about the test cases

Hi all,
I’m about to work on the challenge ’ Drop it’ https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it

But I don’t understand one of the test cases
dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1] .
Why would it return [1, 0, 1] rather than [1, 1] ?
I thought the final array should be the rest of the array once the condition is satisfied? Please could someone let me know? Thank you.

According to the specifications, your function should:

  1. Iterate an array checking if each value in turn fulfils the condition specified in the callback function.
  2. If the callback function returns false, drop the current array item from the array and move onto the next item.
  3. If the callback function returns true, return the array.

If you pass [0, 1, 0, 1] and condition n===1, the callback will return false and drop the first array item. The callback will then return true for the second item and return the array [1, 0, 1].

I see. Thanks a lot!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.