# Intermediate Algorithm Scripting - Drop it

Tell us what’s happening:
Describe your issue in detail here.

Why my code does not work on this case

dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1].
Your code so far

``````function dropElements(arr, func) {
let newArr = [];

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

for (let i=0; i<arr.length; i++) {
if (arr[i]) {
newArr.push(arr[i])
}
}

return newArr;

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

console.log(dropElements([0, 1, 0, 1], function(n) {return n === 1;}))

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

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

``````

User Agent is: `Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36`

Challenge: Intermediate Algorithm Scripting - Drop it

Link to the challenge:

Hello,

push() adds to the end of an array, you need the method that removes the 0 index of an array until the condition is true = number matches.

1 Like

Solved it thanks a lot