time-to-botec

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

repl.txt (1997B)


      1 
      2 {{alias}}( obj, [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`: object value
      8     - `key`: object key
      9 
     10     If a predicate function returns a truthy value, a value is placed in the
     11     first group; otherwise, a value is placed in the second group.
     12 
     13     If provided an empty object with no prototype, the function returns an empty
     14     array.
     15 
     16     The function iterates over an object's own and inherited properties.
     17 
     18     Key iteration order is *not* guaranteed, and, thus, result order is *not*
     19     guaranteed.
     20 
     21     Parameters
     22     ----------
     23     obj: Object|Array|TypedArray
     24         Input object to group.
     25 
     26     options: Object (optional)
     27         Options.
     28 
     29     options.thisArg: any (optional)
     30         Execution context.
     31 
     32     options.returns: string (optional)
     33         If `values`, values are returned; if `keys`, keys are returned; if `*`,
     34         both keys and values are returned. Default: 'values'.
     35 
     36     predicate: Function
     37         Predicate function indicating which group a value in the input object
     38         belongs to.
     39 
     40     Returns
     41     -------
     42     out: Array<Array>|Array
     43         Group results.
     44 
     45     Examples
     46     --------
     47     > function Foo() { this.a = 'beep'; this.b = 'boop'; return this; };
     48     > Foo.prototype = Object.create( null );
     49     > Foo.prototype.c = 'foo';
     50     > Foo.prototype.d = 'bar';
     51     > var obj = new Foo();
     52     > function predicate( v ) { return v[ 0 ] === 'b'; };
     53     > var out = {{alias}}( obj, predicate )
     54     [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
     55 
     56     // Output group results as keys:
     57     > var opts = { 'returns': 'keys' };
     58     > out = {{alias}}( obj, opts, predicate )
     59     [ [ 'a', 'b', 'd' ], [ 'c' ] ]
     60 
     61     // Output group results as key-value pairs:
     62     > opts = { 'returns': '*' };
     63     > out = {{alias}}( obj, opts, predicate )
     64     [ [ ['a', 'beep'], ['b', 'boop'], ['d', 'bar'] ], [ ['c', 'foo' ] ] ]
     65 
     66     See Also
     67     --------
     68