remove distinct

This commit is contained in:
MathMan05 committed 2025-11-26 14:45:19 -06:00
1 parent 781abf950a
commit 12763d1c59
5 files changed
+7 -48

No files matched your search

+1 -1
View File
@@ -255,7 +255,7 @@ export class Channel extends BaseClass {
}
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
recipients = recipients.distinct().filter((x) => x !== creator_user_id);
recipients = [...new Set(recipients.distinct().filter((x) => x !== creator_user_id))];
// TODO: check config for max number of recipients
/** if you want to disallow note to self channels, uncomment the conditional below
-6
View File
@@ -19,10 +19,4 @@ describe("Array extensions", () => {
arr.remove(6);
assert.deepEqual(arr, [1, 2, 4, 5]);
});
it("distinct", () => {
const arr = [1, 2, 2, 3, 3, 3];
assert.deepEqual(arr.distinct(), [1, 2, 3]);
assert.deepEqual([].distinct(), []);
});
});
-10
View File
@@ -20,7 +20,6 @@ declare global {
interface Array<T> {
partition(filter: (elem: T) => boolean): [T[], T[]];
remove(item: T): void;
distinct(): T[];
}
}
@@ -39,10 +38,6 @@ export function arrayRemove<T>(this: T[], item: T): void {
}
}
export function arrayDistinct<T>(this: T[]): T[] {
return Array.from(new Set(this));
}
// register extensions
if (!Array.prototype.partition)
Array.prototype.partition = function <T>(this: T[], filter: (elem: T) => boolean) {
@@ -53,8 +48,3 @@ if (!Array.prototype.remove)
Array.prototype.remove = function <T>(this: T[], item: T) {
return arrayRemove.call(this, item);
};
if (!Array.prototype.distinct)
Array.prototype.distinct = function <T>(this: T[]) {
return arrayDistinct.call(this);
};