some set polyfills

This commit is contained in:
MathMan05 committed 2025-10-29 15:30:15 -05:00
1 parent 2b925d3a9e
commit 345d4535d3
1 file changed
+38 -1
+38 -1
View File
@@ -38,7 +38,44 @@ type favandfreqimp = Omit<
| "heard_sound_frecency"
| "played_sound_frecency"
>;
Set.prototype.intersection ||= function <T>(set: Set<T>) {
const newSet = new Set();
for (const elm of this) {
if (set.has(elm)) {
newSet.add(elm);
}
}
return newSet;
};
Set.prototype.difference ||= function <T>(set: Set<T>) {
const newSet = new Set();
for (const elm of this) {
if (!set.has(elm)) {
newSet.add(elm);
}
}
return newSet;
};
Set.prototype.symmetricDifference ||= function <T>(set: Set<T>) {
const newSet = new Set();
for (const elm of this) {
if (!set.has(elm)) {
newSet.add(elm);
}
}
for (const elm of set) {
if (!this.has(elm)) {
newSet.add(elm);
}
}
return newSet;
};
Set.prototype.isDisjointFrom ||= function <T>(set: Set<T>) {
return this.symmetricDifference(set).size === 0;
};
Set.prototype.union ||= function <T>(set: Set<T>) {
return new Set([...this, ...set]);
};
export class Favorites {
owner: Localuser;
// ----- stuff that needs to store ----