time-to-botec

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

repl.txt (1841B)


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