From ea4cb844b8dd74e48394d5609f544a49baf28686 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:38:36 +0100 Subject: set_filter with running hole --- rules.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rules.js b/rules.js index 4a45d5f..90f0f7c 100644 --- a/rules.js +++ b/rules.js @@ -2611,10 +2611,15 @@ function set_delete(set, item) { } function set_filter(set, predicate_fn) { - for (let i = set.length - 1; i >= 0; i--) { - if (!predicate_fn(set[i])) - array_remove(set, i) + let hole = 0 + for (let i = 0; i < set.length; i++) { + if (predicate_fn(set[i])) { + if (hole !== i) + set[hole] = set[i] + hole++ + } } + set.length = hole } function set_toggle(set, item) { -- cgit v1.2.3