Drop it (can't past 1 test, help please)

Tell us what’s happening:

Hey. I dont know why my code doesnt work. It’s supposed to shift a value from an array if func is false, but when the biggest value in an array is lower than the value for which function is true it doesnt shift all the the values from the array? it just returns [3,4] instead of []. Help please

Your code so far


function dropElements(arr, func) {
  
  
  for (var i = 0; i < arr.length; i++) {
    if (!func(arr[0])) {                       // if func is false
      arr.shift();                                // shift the value from an array
      console.log(arr);
    } else {
     console.log("func = true")        // if its true do nothing, and the value stays
    }
  }

  return arr;                                  // returns [3,4] except of an empty array []  Why?
  
  
}

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/70.0.3538.102 Safari/537.36.

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

This problem ( basically the same) is being posted few days ago^^

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