Refactor uniq function for TS compliance and efficiency improvements

This commit refactors the `uniq` function found in the emoji utilities to accept an explicitly defined array as an argument, improving overall TypeScript compliance. It also replaces the `.indexOf` method with the more efficient `.includes` method for better performance.
This commit is contained in:
taichi221228 2024-05-02 13:37:22 +09:00 committed by Eugen Rochko
parent 728ca82d79
commit d922b619e3

View File

@ -200,25 +200,22 @@ function getData(...[emoji, skin, set]: GetDataArgs) {
/* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */ /* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
} }
/* eslint-disable */ function uniq(arr: []) {
// @ts-expect-error
function uniq(arr) {
// @ts-expect-error
return arr.reduce((acc, item) => { return arr.reduce((acc, item) => {
if (acc.indexOf(item) === -1) { if (!acc.includes(item)) {
acc.push(item); acc.push(item);
} }
return acc; return acc;
}, []); }, []);
} }
/* eslint-disable */
// @ts-expect-error // @ts-expect-error
function intersect(a, b) { function intersect(a, b) {
const uniqA = uniq(a); const uniqA = uniq(a);
const uniqB = uniq(b); const uniqB = uniq(b);
// @ts-expect-error
return uniqA.filter((item) => uniqB.indexOf(item) >= 0); return uniqA.filter((item) => uniqB.indexOf(item) >= 0);
} }