time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (1823B)


      1 
      2 {{alias}}( collection, [options,] groups )
      3     Groups values as arrays associated with distinct keys.
      4 
      5     If provided an empty collection, the function returns an empty object.
      6 
      7     Parameters
      8     ----------
      9     collection: Array|TypedArray|Object
     10         Input collection to group. If provided an object, the object must be
     11         array-like (excluding strings and functions).
     12 
     13     options: Object (optional)
     14         Options.
     15 
     16     options.returns: string (optional)
     17         If `values`, values are returned; if `indices`, indices are returned; if
     18         `*`, both indices and values are returned. Default: 'values'.
     19 
     20     groups: Array|TypedArray|Object
     21         A collection defining which group an element in the input collection
     22         belongs to. Each value in `groups` should resolve to a value which can
     23         be serialized as an object key. If provided an object, the object must
     24         be array-like (excluding strings and functions).
     25 
     26     Returns
     27     -------
     28     out: Object
     29         Group results.
     30 
     31     Examples
     32     --------
     33     > var collection = [ 'beep', 'boop', 'foo', 'bar' ];
     34     > var groups = [ 'b', 'b', 'f', 'b' ];
     35     > var out = {{alias}}( collection, groups )
     36     { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
     37     > groups = [ 1, 1, 2, 1 ];
     38     > out = {{alias}}( collection, groups )
     39     { '1': [ 'beep', 'boop', 'bar' ], '2': [ 'foo' ] }
     40 
     41     // Output group results as indices:
     42     > groups = [ 'b', 'b', 'f', 'b' ];
     43     > var opts = { 'returns': 'indices' };
     44     > out = {{alias}}( collection, opts, groups )
     45     { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
     46 
     47     // Output group results as index-element pairs:
     48     > opts = { 'returns': '*' };
     49     > out = {{alias}}( collection, opts, groups )
     50     { 'b': [ [0, 'beep'], [1, 'boop'], [3, 'bar'] ], 'f': [ [2, 'foo'] ] }
     51 
     52     See Also
     53     --------
     54