mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-23 21:32:29 +00:00
some set polyfills
This commit is contained in:
1 parent
2b925d3a9e
commit
345d4535d3
1 file changed
+38
-1
@@ -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 ----
|
||||
|
||||
Reference in new issue
Block a user