repl.txt (3382B)
1 2 {{alias}}( N, x, stride, clbk[, thisArg] ) 3 Calculates the range of a strided array via a callback function, ignoring 4 `NaN` values. 5 6 The `N` and `stride` parameters determine which elements in `x` are accessed 7 at runtime. 8 9 Indexing is relative to the first index. To introduce an offset, use typed 10 array views. 11 12 If `N <= 0`, the function returns `x` unchanged. 13 14 The callback function is provided four arguments: 15 16 - value: array element 17 - aidx: array index 18 - sidx: strided index (offset + aidx*stride) 19 - array: the input array 20 21 The callback function should return a numeric value. 22 23 If the callback function returns `NaN`, the value is ignored. 24 25 If the callback function does not return any value (or equivalently, 26 explicitly returns `undefined`), the value is ignored. 27 28 Parameters 29 ---------- 30 N: integer 31 Number of indexed elements. 32 33 x: Array|TypedArray|Object 34 Input array/collection. If provided an object, the object must be array- 35 like (excluding strings and functions). 36 37 stride: integer 38 Index increment for `x`. 39 40 clbk: Function 41 Callback function. 42 43 thisArg: any (optional) 44 Execution context. 45 46 Returns 47 ------- 48 out: number 49 Range. 50 51 Examples 52 -------- 53 // Standard Usage: 54 > function accessor( v ) { return v * 2.0; }; 55 > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, -1.0, -3.0 ]; 56 > {{alias}}( x.length, x, 1, accessor ) 57 18.0 58 59 // Using `N` and `stride` parameters: 60 > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0, 1.0 ]; 61 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 62 > {{alias}}( N, x, 2, accessor ) 63 14.0 64 65 // Using view offsets: 66 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); 67 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 68 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 69 > {{alias}}( N, x1, 2, accessor ) 70 8.0 71 72 {{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] ) 73 Calculates the range of a strided array via a callback function, ignoring 74 `NaN` values and using alternative indexing semantics. 75 76 While typed array views mandate a view offset based on the underlying 77 buffer, the `offset` parameter supports indexing semantics based on a 78 starting index. 79 80 Parameters 81 ---------- 82 N: integer 83 Number of indexed elements. 84 85 x: Array|TypedArray|Object 86 Input array/collection. If provided an object, the object must be array- 87 like (excluding strings and functions). 88 89 stride: integer 90 Index increment for `x`. 91 92 offset: integer 93 Starting index of `x`. 94 95 clbk: Function 96 Callback function. 97 98 thisArg: any (optional) 99 Execution context. 100 101 Returns 102 ------- 103 out: number 104 Range. 105 106 Examples 107 -------- 108 // Standard Usage: 109 > function accessor( v ) { return v * 2.0; }; 110 > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, -1.0, -3.0 ]; 111 > {{alias}}.ndarray( x.length, x, 1, 0, accessor ) 112 18.0 113 114 // Using an index offset: 115 > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; 116 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 117 > {{alias}}.ndarray( N, x, 2, 1, accessor ) 118 8.0 119 120 See Also 121 -------- 122