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