@beenotung/tslib
Version:
utils library in Typescript
36 lines (35 loc) • 763 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toggleSet = toggleSet;
exports.setMinus = setMinus;
exports.setAdd = setAdd;
exports.setMinusInplace = setMinusInplace;
exports.setAddInplace = setAddInplace;
function toggleSet(s, a) {
if (s.has(a)) {
s.delete(a);
}
else {
s.add(a);
}
}
function setMinus(a, b) {
const res = new Set();
a.forEach(x => {
if (!b.has(x)) {
res.add(x);
}
});
return res;
}
function setAdd(a, b) {
const res = new Set(a);
b.forEach(x => res.add(x));
return res;
}
function setMinusInplace(to, from) {
from.forEach(x => to.delete(x));
}
function setAddInplace(to, from) {
from.forEach(x => to.add(x));
}