time-to-botec

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

repl.txt (1824B)


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