@stdlib/array
Version:
Arrays.
35 lines (26 loc) • 840 B
Plain Text
{{alias}}( x, groups )
Groups elements as arrays associated with distinct keys.
If provided an empty array, the function returns an empty object.
Parameters
----------
x: ArrayLike
Input array.
groups: ArrayLike
An array defining which group an element in the input array belongs to.
Each value in `groups` should resolve to a value which can be serialized
as an object key.
Returns
-------
out: Object
Group results.
Examples
--------
> var x = [ 'beep', 'boop', 'foo', 'bar' ];
> var g = [ 'b', 'b', 'f', 'b' ];
> var out = {{alias}}( x, g )
{ 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
> g = [ 1, 1, 2, 1 ];
> out = {{alias}}( x, g )
{ '1': [ 'beep', 'boop', 'bar' ], '2': [ 'foo' ] }
See Also
--------