@stdlib/array
Version:
Arrays.
35 lines (26 loc) • 879 B
Plain Text
{{alias}}( x, groups )
Groups element entries 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': [ [0,'beep'], [1,'boop'], [3,'bar'] ], 'f': [ [2,'foo'] ] }
> g = [ 1, 1, 2, 1 ];
> out = {{alias}}( x, g )
{ '1': [ [0,'beep'], [1,'boop'], [3,'bar'] ], '2': [ [2,'foo'] ] }
See Also
--------