Implement an Element Skipper - Implement an Element Skipper

Tell us what’s happening:

I am not passing the 5th and 6th tests. I think I understand why I am not passing the 5th test, and I am working on that, but I don’t understand the 6th test. I feel like my code should have it pass because it passes all the other tests, but what is happening is that the array that is returned is [4] not [7, 4].

Failed:5. dropElements([1, 2, 3, 4], function(n) {return n > 5;}) should return .
Failed:6. dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}) should return [7, 4].

Your code so far


const dropElements = (arr, func) => {
   
  for(let i = 0; i < arr.length; i++){
    const index = arr.indexOf(i)
   
   if(func(i)){
      return arr.slice(index)
    }
  }
}

console.log(dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}))
console.log(dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}))
console.log(dropElements([1, 2, 3, 4], function(n) {return n > 5;}))
console.log(dropElements([0, 1, 0, 1], function(n) {return n === 1;}))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Implement an Element Skipper - Implement an Element Skipper

Hi @lynders

Try console logging the index variable wherever it is used.

Happy coding

what is this line doing?