repl.txt (1297B)
1 2 {{alias}}( collection, [options,] indicator ) 3 Groups values according to an indicator function and returns group counts. 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 indicator: Function 28 Indicator function specifying which group an element in the input 29 collection belongs to. 30 31 Returns 32 ------- 33 out: Object 34 Group results. 35 36 Examples 37 -------- 38 > function indicator( v ) { 39 ... if ( v[ 0 ] === 'b' ) { 40 ... return 'b'; 41 ... } 42 ... return 'other'; 43 ... }; 44 > var collection = [ 'beep', 'boop', 'foo', 'bar' ]; 45 > var out = {{alias}}( collection, indicator ) 46 { 'b': 3, 'other': 1 } 47 48 See Also 49 -------- 50