diff options
author | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-11-22 16:38:36 +0100 |
---|---|---|
committer | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-11-22 16:38:36 +0100 |
commit | ea4cb844b8dd74e48394d5609f544a49baf28686 (patch) | |
tree | ab4d6c5b9db70bef690de892c8aaacc1df248c86 | |
parent | c15c78be6080ad980d2fc74dc8696bb54c8500a3 (diff) | |
download | votes-for-women-ea4cb844b8dd74e48394d5609f544a49baf28686.tar.gz |
set_filter with running hole
-rw-r--r-- | rules.js | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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) { |