I wouldn´t have created the times variable at all, instead I would have just added “< arr.length” inside the for loop, as usual. I tried that, but it doesn´t work. I don´t really understand the difference between both of these. Could anyone explain?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

So follow the logic: Loop through the array a certain number of times, and, if the first element each time doesn’t return true from a given function, remove it.

Each time, we’re shortening the array, so arr.length will be changing. But we still may want to process through every element, so we assign arr.length to a variable before, so that it remains constant (thus the famous coder quote, “Variables won’t, constants aren’t.”)

If we used arr.length each time, that number will change. But i is going to increment, regardless – by using arr.length as it gets shorter and shorter, we would eventually have elements not getting hit.

If, instead, we used a do/while, we could simply remove elements and, while the arr.length && !func(arr[0]) values return true, keep removing the first element. That would have much the same end result, without the pesky i and the extra variable for times.