summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-04 14:04:54 +0200
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-04 14:04:54 +0200
commit0c4fcbe674f5aae34f0fee2380de6c001a167d1b (patch)
tree98ebdd43c20e600ef3d3c39126009930b56b7f87
parentecf109f6096d1b6c82e5eae64ed5d0bc5638f372 (diff)
downloadalgeria-0c4fcbe674f5aae34f0fee2380de6c001a167d1b.tar.gz
GC optimization
-rw-r--r--rules.js10
1 files changed, 5 insertions, 5 deletions
diff --git a/rules.js b/rules.js
index 97b275b..c1305d4 100644
--- a/rules.js
+++ b/rules.js
@@ -2028,11 +2028,11 @@ function set_toggle(set, item) {
return array_insert(set, a, item)
}
-function is_subset_with_multiplicity(set, subset) {
- return subset.every(val => set.includes(val)
- && subset.filter(el => el === val).length
- <=
- set.filter(el => el === val).length)
+function is_subset_with_multiplicity(multiset, subset) {
+ const occurrences = (arr, val) =>
+ arr.reduce((acc, el) => (el === val ? acc + 1 : acc), 0)
+
+ return !subset.some(val => (occurrences(subset, val) > occurrences(multiset, val)))
}
// Fast deep copy for objects without cycles