Ah, I get it now. I realize I’m supposed to first pass the length of arr to a variable in order to preserve it (keep it the same length). We need ‘i’ to iterate through the array. We don’t need i in the body of the for-loop though because arr.shift() pops off the first element of the array with each iteration.
function dropElements(arr, func) {
// Drop them elements.
let i = 0;
let _arr = [...arr];
for (i; i < _arr.length; i++) {
let result = func(_arr[i]);
if (result) {
return arr;
} else {
arr.splice(0, 1);
}
}
return [];
}
dropElements([1, 2, 3], function (n) { return n > 0; })