time-to-botec

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

repl.txt (1890B)


      1 
      2 {{alias}}( obj, [options,] indicator )
      3     Group values according to an indicator function.
      4 
      5     When invoked, the indicator function is provided two arguments:
      6 
      7     - `value`: object value
      8     - `key`: object key
      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 object, the function returns an empty object.
     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     indicator: Function
     36         Indicator function indicating which group a value in the input object
     37         belongs to.
     38 
     39     Returns
     40     -------
     41     out: Object
     42         Group results.
     43 
     44     Examples
     45     --------
     46     > function indicator( v ) {
     47     ...     if ( v[ 0 ] === 'b' ) {
     48     ...         return 'b';
     49     ...     }
     50     ...     return 'other';
     51     ... };
     52     > var obj = { 'a': 'beep', 'b': 'boop', 'c': 'foo', 'd': 'bar' };
     53     > var out = {{alias}}( obj, indicator )
     54     { 'b': [ 'beep', 'boop', 'bar' ], 'other': [ 'foo' ] }
     55 
     56     // Output group results as keys:
     57     > var opts = { 'returns': 'keys' };
     58     > out = {{alias}}( obj, opts, indicator )
     59     { 'b': [ 'a', 'b', 'd' ], 'other': [ 'c' ] }
     60 
     61     // Output group results as key-value pairs:
     62     > opts = { 'returns': '*' };
     63     > out = {{alias}}( obj, opts, indicator )
     64     { 'b': [['a','beep'], ['b','boop'], ['d','bar']], 'other': [['c','foo' ]] }
     65 
     66     See Also
     67     --------
     68