groupBy
groupBy<
T,Keys>(iterable,keysOf,comparisonStrategy?):GroupedBy<T,Keys>
Defined in: group/group-by.ts:43
Groups the items of an iterable by the key returned from each accessor, one
nested Map level per accessor.
Groups are created in the order their keys first occur. Time complexity: O(n
· k) for k accessors, O(n) additional space, under the default
"sameValueZero".
keysOf is an array rather than a rest parameter because a trailing
comparisonStrategy is itself allowed to be a function, so it could not be
told apart from one more accessor.
Type Parameters
Section titled “Type Parameters”T
Keys extends readonly [unknown, unknown]
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
keysOf
Section titled “keysOf”{ [I in string | number | symbol]: Callable<[T], Keys[I]> }
One or more functions taking an item and returning a group key, outermost level first.
comparisonStrategy?
Section titled “comparisonStrategy?”EqualityComparisonStrategy<Keys[number], Keys[number]> = "sameValueZero"
How keys are compared. Only "sameValueZero" is
supported, because grouping is backed by a Map, whose key equality is
fixed; any other strategy would need a different backing structure and a
different complexity.
Returns
Section titled “Returns”GroupedBy<T, Keys>
Nested maps from each group key to the items in that group.
Throws
Section titled “Throws”If comparisonStrategy is not
"sameValueZero".