group

Variable

按 `getGroupId` 返回的分组标识把数组分组,得到 `{ 分组标识: 该组元素数组 }` 的对象

Signature

const group: <T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key) => Partial<Record<Key, T[]>>

Examples

group([{ source: 'a' }, { source: 'b' }, { source: 'a' }], (item) => item.source)
// { a: [{ source: 'a' }, { source: 'a' }], b: [{ source: 'b' }] }

Source

node_modules/.pnpm/radash@12.1.1/node_modules/radash/dist/index.d.ts:6