summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-22 16:38:36 +0100
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-22 16:38:36 +0100
commitea4cb844b8dd74e48394d5609f544a49baf28686 (patch)
treeab4d6c5b9db70bef690de892c8aaacc1df248c86
parentc15c78be6080ad980d2fc74dc8696bb54c8500a3 (diff)
downloadvotes-for-women-ea4cb844b8dd74e48394d5609f544a49baf28686.tar.gz
set_filter with running hole
-rw-r--r--rules.js11
1 files 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) {