You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion.
663
+
664
+
```javascript
665
+
functionreducer( acc, v ) {
666
+
return ( acc && v );
667
+
}
668
+
669
+
var Float64ArrayFE =fixedEndianFactory( 'float64' );
670
+
671
+
var arr =newFloat64ArrayFE( 'little-endian', [ 1.0, 0.0, 1.0 ] );
672
+
// returns <Float64ArrayFE>
673
+
674
+
var out =arr.reduceRight( reducer );
675
+
// returns 0.0
676
+
```
677
+
678
+
The reducer function is provided four arguments:
679
+
680
+
-**acc**: accumulated result.
681
+
-**value**: current array element.
682
+
-**index**: current array element index.
683
+
-**arr**: the array on which this method was called.
684
+
685
+
By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument.
686
+
687
+
```javascript
688
+
functionreducer( acc, v ) {
689
+
if ( v ) {
690
+
return acc +1;
691
+
}
692
+
return acc;
693
+
}
694
+
695
+
var Float64ArrayFE =fixedEndianFactory( 'float64' );
696
+
697
+
var arr =newFloat64ArrayFE( 'little-endian', [ 1.0, 0.0, 1.0 ] );
* Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion.
816
+
*
817
+
* @name reduceRight
818
+
* @memberof TypedArray.prototype
819
+
* @type {Function}
820
+
* @param {Function} reducer - callback function
821
+
* @param {*} [initialValue] - initial value
822
+
* @throws {TypeError} `this` must be a typed array
823
+
* @throws {Error} if not provided an initial value, the array must have at least one element
0 commit comments