summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {