mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-04-01 00:33:32 +02:00
Add difference, intersection, and union methods to RealSet.
This commit is contained in:
@@ -395,6 +395,21 @@ RealSet.prototype.add = function RealSet_add(val) {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RealSet.prototype.difference = function RealSet_difference(set) {
|
||||||
|
return RealSet(i for (i of this) if (!set.has(i)));
|
||||||
|
};
|
||||||
|
|
||||||
|
RealSet.prototype.intersection = function RealSet_intersection(set) {
|
||||||
|
return RealSet(i for (i of this) if (set.has(i)));
|
||||||
|
};
|
||||||
|
|
||||||
|
RealSet.prototype.union = function RealSet_union(set) {
|
||||||
|
let res = RealSet(this);
|
||||||
|
for (let item of set)
|
||||||
|
res.add(item);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for managing sets of strings. Given an array, returns an
|
* Utility for managing sets of strings. Given an array, returns an
|
||||||
* object with one key for each value thereof.
|
* object with one key for each value thereof.
|
||||||
|
|||||||
Reference in New Issue
Block a user