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.
1715
+
1716
+
```javascript
1717
+
var real =require( '@stdlib/complex-real' );
1718
+
var imag =require( '@stdlib/complex-imag' );
1719
+
var cadd =require( '@stdlib/math-base-ops-cadd' );
1720
+
1721
+
var arr =newComplex128Array( 3 );
1722
+
1723
+
arr.set( [ 1.0, 1.0 ], 0 );
1724
+
arr.set( [ 2.0, 2.0 ], 1 );
1725
+
arr.set( [ 3.0, 3.0 ], 2 );
1726
+
1727
+
var z =arr.reduceRight( cadd );
1728
+
// returns <Complex128>
1729
+
1730
+
var re =real( z );
1731
+
// returns 6.0
1732
+
1733
+
var im =imag( z );
1734
+
// returns 6.0
1735
+
```
1736
+
1737
+
The reducer function is provided four arguments:
1738
+
1739
+
-**acc**: accumulated result.
1740
+
-**value**: current array element.
1741
+
-**index**: current array element index.
1742
+
-**arr**: the array on which this method was called.
1743
+
1744
+
By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument.
0 commit comments