FMHYedit/docs/.vitepress/utils.ts
2024-02-25 01:31:53 +00:00

13 lines
248 B
TypeScript

export function groupBy<T, K extends keyof any>(
arr: T[],
key: (i: T) => K
): Record<K, T[]> {
return arr.reduce(
(groups, item) => {
;(groups[key(item)] ||= []).push(item)
return groups
},
{} as Record<K, T[]>
)
}