/
softailor
/
gridient
Обзор
Документация
Войти
/
softailor
/
gridient
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/src/utils/arrayUtils.ts
45 строк
1 KB
Jenkins
Auto add
18 фев 2026, 10:19
18 фев 2026, 10:19
1e6c4f8
Код
Авторство
О чём код?
export const onlyUnique = (value: string, index: number, array: string[]) => { return array.indexOf(value) === index; }; // export const groupByFieldName = (items: unknown[], key: string) => { // return items.reduce((result, item) => { // result[item[key]] = [...(result[item[key]] || []), item]; // return result; // }, {}); // }; export const groupByFieldName = <T>(items: T[], key: keyof T | string): Record<string, T[]> => { return items.reduce( (result, item) => { const keyValue = (item as Record<string, unknown>)[key as string]; const keyStr = String(keyValue); if (!result[keyStr]) { result[keyStr] = []; } result[keyStr].push(item); return result; }, {} as Record<string, T[]>, ); }; export const compareArrays = (arr1: unknown[], arr2: unknown[]): boolean => arr1.every((elem, index) => { if (JSON.stringify(elem) === JSON.stringify(arr2[index])) { return true; } else { return false; } }); /** * Removes duplicate values from an array * @param arr - Array to deduplicate * @returns New array with unique values */ export const deduplicateArray = <T>(arr: T[]): T[] => { return Array.from(new Set(arr)); };