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
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