Tell us what’s happening:
Not sure why my code isn’t working. Seems right to me: create a for loop to iterate through the array, when the first element passes the function, return the remaining array. Otherwise, if the element doesn’t pass the function, remove it from the array and test the next element in the array.
Your code so far
function dropElements(arr, func) {
for (var i = 0; i < arr.length; i ++) {
if (func(arr[i])) {
return arr;
} else{
arr.shift(arr[i]);
}
}
return arr;
}
dropElements([1, 2, 3], function(n) {return n < 3; });
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: