@serenity-is/corelib / toGrouping
Function: toGrouping()
toGrouping<
TItem>(items,getKey):Grouping<TItem>
Defined in: src/compat/arrays-compat.ts:212
Groups an array into a dictionary keyed by getKey.
Type Parameters
TItem
TItem
Parameters
items
TItem[]
Array to group.
getKey
(x) => any
Callback returning the group key for an element; null/undefined is normalized to "".
Returns
Grouping<TItem>
A Grouping dictionary whose values are arrays of matching elements. Uses a null-prototype object.
Remarks
Lighter alternative to groupBy when ordered metadata is not needed.
Example
toGrouping([1, 2, 3], x => x % 2 == 0 ? "even" : "odd"); // { odd: [1, 3], even: [2] }