Drop it: why this code is not working

Tell us what’s happening:

Your code so far


function dropElements(arr, func) {

for(let i =0; i <= arr.length; i++){
       if(!func(arr[0])){
   arr.shift();
  }
  
}
  return arr;
}


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

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it/

You have to use Array.splice() to remove the first element from an array.

Here is your code:

function dropElements(arr, func) {
  while(!func(arr[0])) arr.splice(0, 1);
  return arr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });

@camperextraordinaire
Oh I didn’t knew that. Thanks!