FMHYedit/.vitepress/utils.ts
2024-07-10 04:05:54 +00:00

14 lines
323 B
TypeScript

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