time-to-botec

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

repl.txt (1890B)


      1 
      2 {{alias}}( collection, [options,] indicator )
      3     Groups values according to an indicator function.
      4 
      5     When invoked, the indicator function is provided two arguments:
      6 
      7     - `value`: collection value
      8     - `index`: collection index
      9 
     10     The value returned by an indicator function should be a value which can be
     11     serialized as an object key.
     12 
     13     If provided an empty collection, the function returns an empty object.
     14 
     15     Parameters
     16     ----------
     17     collection: Array|TypedArray|Object
     18         Input collection to group. If provided an object, the object must be
     19         array-like (excluding strings and functions).
     20 
     21     options: Object (optional)
     22         Options.
     23 
     24     options.thisArg: any (optional)
     25         Execution context.
     26 
     27     options.returns: string (optional)
     28         If `values`, values are returned; if `indices`, indices are returned; if
     29         `*`, both indices and values are returned. Default: 'values'.
     30 
     31     indicator: Function
     32         Indicator function specifying which group an element in the input
     33         collection belongs to.
     34 
     35     Returns
     36     -------
     37     out: Object
     38         Group results.
     39 
     40     Examples
     41     --------
     42     > function indicator( v ) {
     43     ...     if ( v[ 0 ] === 'b' ) {
     44     ...         return 'b';
     45     ...     }
     46     ...     return 'other';
     47     ... };
     48     > var collection = [ 'beep', 'boop', 'foo', 'bar' ];
     49     > var out = {{alias}}( collection, indicator )
     50     { 'b': [ 'beep', 'boop', 'bar' ], 'other': [ 'foo' ] }
     51 
     52     // Output group results as indices:
     53     > var opts = { 'returns': 'indices' };
     54     > out = {{alias}}( collection, opts, indicator )
     55     { 'b': [ 0, 1, 3 ], 'other': [ 2 ] }
     56 
     57     // Output group results as index-value pairs:
     58     > opts = { 'returns': '*' };
     59     > out = {{alias}}( collection, opts, indicator )
     60     { 'b': [ [0, 'beep'], [1, 'boop'], [3, 'bar'] ], 'other': [ [2, 'foo' ] ] }
     61 
     62     See Also
     63     --------
     64