diff --git a/src/webpage/favorites.ts b/src/webpage/favorites.ts index 3ffb611..f65f6cf 100644 --- a/src/webpage/favorites.ts +++ b/src/webpage/favorites.ts @@ -38,7 +38,44 @@ type favandfreqimp = Omit< | "heard_sound_frecency" | "played_sound_frecency" >; - +Set.prototype.intersection ||= function (set: Set) { + const newSet = new Set(); + for (const elm of this) { + if (set.has(elm)) { + newSet.add(elm); + } + } + return newSet; +}; +Set.prototype.difference ||= function (set: Set) { + const newSet = new Set(); + for (const elm of this) { + if (!set.has(elm)) { + newSet.add(elm); + } + } + return newSet; +}; +Set.prototype.symmetricDifference ||= function (set: Set) { + 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 (set: Set) { + return this.symmetricDifference(set).size === 0; +}; +Set.prototype.union ||= function (set: Set) { + return new Set([...this, ...set]); +}; export class Favorites { owner: Localuser; // ----- stuff that needs to store ----