You’re right - you’re almost there. What I always find helps when I’m stuck on something like that is to write more expressive console.logs, to drill into what’s going wrong.
I just did this with your code, I added lines like this
console.log("filtered line 27: " + filtered)
so it would tell me what the value of filtered was at a specific line. Doing this I was able to find the mistake, I think. You set the filtered array correctly
filtered = arr.filter(x)
But you never assign it to ‘arr’ so the next time it comes round the loop, it starts with the original array again, not the one you’ve just filtered. To fix it, you just need to add
arr = filtered;
before the end of the loop.
@Mizu’s points are valid (though it’s a bit harsh to lead with ‘there is much stuff going wrong…’ ) You’ll save yourself a lot of pain if you make yourself declare variables explicitly - I find it’s best to add “use strict”; to everything to make myself do this because otherwise much confusion can creep in.