1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-06 12:55:45 +01:00

Add difference, intersection, and union methods to RealSet.

This commit is contained in:
Kris Maglione
2014-02-22 10:20:09 -08:00
parent 619b414ca7
commit 2277a5b238

View File

@@ -395,6 +395,21 @@ RealSet.prototype.add = function RealSet_add(val) {
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
* object with one key for each value thereof.