@thi.ng/associative
Version:
ES Map/Set-compatible implementations with customizable equality semantics & supporting operations
22 lines (21 loc) • 507 B
JavaScript
import { copy } from "@thi.ng/object-utils/copy";
import { empty } from "@thi.ng/object-utils/empty";
import { __combineSet } from "./internal/combine.js";
import { into } from "./into.js";
const difference = (a, b, out) => {
if (a === b) {
return out || empty(a, Set);
}
out = out ? into(out, a) : copy(a, Set);
for (let i of b) {
out.delete(i);
}
return out;
};
function differenceR(src) {
return __combineSet(differenceR, difference, src);
}
export {
difference,
differenceR
};