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 order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
1628
+
1629
+
```javascript
1630
+
var real =require( '@stdlib/complex/real' );
1631
+
var imag =require( '@stdlib/complex/imag' );
1632
+
var cadd =require( '@stdlib/math/base/ops/cadd' );
1633
+
1634
+
var arr =newComplex128Array( 3 );
1635
+
1636
+
arr.set( [ 1.0, 1.0 ], 0 );
1637
+
arr.set( [ 2.0, 2.0 ], 1 );
1638
+
arr.set( [ 3.0, 3.0 ], 2 );
1639
+
1640
+
var z =arr.reduce( cadd );
1641
+
// returns <Complex128>
1642
+
1643
+
var re =real( z );
1644
+
// returns 6.0
1645
+
1646
+
var im =imag( z );
1647
+
// returns 6.0
1648
+
```
1649
+
1650
+
The reducer function is provided four arguments:
1651
+
1652
+
-**acc**: accumulated result.
1653
+
-**value**: current array element.
1654
+
-**index**: current array element index.
1655
+
-**arr**: the array on which this method was called.
1656
+
1657
+
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.
* Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
870
+
*
871
+
* @param reducer - callback function
872
+
* @param initialValue - initial value
873
+
* @returns accumulated result
874
+
*
875
+
* @example
876
+
* var real = require( '@stdlib/complex/real' );
877
+
* var imag = require( '@stdlib/complex/imag' );
878
+
* var cadd = require( '@stdlib/math/base/ops/cadd' );
* Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
1701
+
*
1702
+
* @name reduce
1703
+
* @memberof Complex128Array.prototype
1704
+
* @type {Function}
1705
+
* @param {Function} reducer - callback function
1706
+
* @param {*} [initialValue] - initial value
1707
+
* @throws {TypeError} `this` must be a complex number array
1708
+
* @throws {TypeError} first argument must be a function
1709
+
* @throws {Error} if not provided an initial value, the array must have at least one element
1710
+
* @returns {*} accumulated result
1711
+
*
1712
+
* @example
1713
+
* var real = require( '@stdlib/complex/real' );
1714
+
* var imag = require( '@stdlib/complex/imag' );
1715
+
* var cadd = require( '@stdlib/math/base/ops/cadd' );
0 commit comments