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