Implement an Element Skipper - Implement an Element Skipper

Tell us what’s happening:

I need some guidance for this test, not sure how to write the logic to get the correct positions when looping through the array

Your code so far

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


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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Implement an Element Skipper - Implement an Element Skipper

Hi @wcrase

Try adding the following console log to the editor.

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

What do you expect the function call to return?

Happy coding

it should return [5,2, 3,4] but how do I do that?

The call returns [5, 3, 4] which are numbers greater than or equal to three.

You are using the slice method, so finds the first index and return all numbers after that, whether or not they satisfy the condition in the supplied function.

You need a way to check each element in the array.

im not sure what I need to do tbh

any other hints that you could give me for this?

can you explain what is this line doing?