[Solved] Stuck with Drop it Algorithm Challenge

[Solved] Stuck with Drop it Algorithm Challenge
0

#1

Hello guys,

I have written the following code:

function dropElements(arr, func) {
  var newArray = arr.filter(func);
 return newArray;  
}

So the problem here is, that I don’t pass the following tests:

dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1]
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2]

I understand what needs to be done. If the first item is found which gives back true, the script should stop and return the rest of the array ( so the script should stop checking the other indexes, maybe a break will do the job?)

Thank you for your help!

Update 1:
So after struggling a little bit with this, I found the solution with slice():

function dropElements(arr, func) {
  var newArray = [];
  for(var i = 0; i < arr.length; i++){
    if(func(arr[i])){
     newArray = arr.slice(i);
     break;
    }
  }
  return newArray;
}