UNPKG

@aws-amplify/analytics

Version:

Analytics category of aws-amplify

17 lines (14 loc) 412 B
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 export const groupBy = <T>( getGroupId: (x: T) => string, list: T[], ): Record<string, T[]> => { return list.reduce( (result, current) => { const groupId = getGroupId(current); return { ...result, [groupId]: [...(result[groupId] ?? []), current] }; }, {} as Record<string, T[]>, ); };