repl.txt (1868B)
1 2 {{alias}}( arr[, options] ) 3 Flattens an array. 4 5 Parameters 6 ---------- 7 arr: Array 8 Input array. 9 10 options: Object (optional) 11 Options. 12 13 options.depth: integer (optional) 14 Maximum depth to flatten. 15 16 options.copy: boolean (optional) 17 Boolean indicating whether to deep copy array elements. Default: false. 18 19 Returns 20 ------- 21 out: Array 22 Flattened array. 23 24 Examples 25 -------- 26 > var arr = [ 1, [ 2, [ 3, [ 4, [ 5 ], 6 ], 7 ], 8 ], 9 ]; 27 > var out = {{alias}}( arr ) 28 [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] 29 30 // Set the maximum depth: 31 > arr = [ 1, [ 2, [ 3, [ 4, [ 5 ], 6 ], 7 ], 8 ], 9 ]; 32 > out = {{alias}}( arr, { 'depth': 2 } ) 33 [ 1, 2, 3, [ 4, [ 5 ], 6 ], 7, 8, 9 ] 34 > var bool = ( arr[ 1 ][ 1 ][ 1 ] === out[ 3 ] ) 35 true 36 37 // Deep copy: 38 > arr = [ 1, [ 2, [ 3, [ 4, [ 5 ], 6 ], 7 ], 8 ], 9 ]; 39 > out = {{alias}}( arr, { 'depth': 2, 'copy': true } ) 40 [ 1, 2, 3, [ 4, [ 5 ], 6 ], 7, 8, 9 ] 41 > bool = ( arr[ 1 ][ 1 ][ 1 ] === out[ 3 ] ) 42 false 43 44 45 {{alias}}.factory( dims[, options] ) 46 Returns a function for flattening arrays having specified dimensions. 47 48 The returned function does not validate that input arrays actually have the 49 specified dimensions. 50 51 Parameters 52 ---------- 53 dims: Array<integer> 54 Dimensions. 55 56 options: Object (optional) 57 Options. 58 59 options.copy: boolean (optional) 60 Boolean indicating whether to deep copy array elements. Default: false. 61 62 Returns 63 ------- 64 fcn: Function 65 Flatten function. 66 67 Examples 68 -------- 69 > var flatten = {{alias}}.factory( [ 2, 2 ], { 70 ... 'copy': false 71 ... }); 72 > var out = flatten( [ [ 1, 2 ], [ 3, 4 ] ] ) 73 [ 1, 2, 3, 4 ] 74 > out = flatten( [ [ 5, 6 ], [ 7, 8 ] ] ) 75 [ 5, 6, 7, 8 ] 76 77 See Also 78 -------- 79