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.
585
+
586
+
```javascript
587
+
functionreducer( acc, v ) {
588
+
return ( acc && v );
589
+
}
590
+
591
+
var Float64ArrayFE =fixedEndianFactory( 'float64' );
592
+
593
+
var arr =newFloat64ArrayFE( 'little-endian', [ 1.0, 0.0, 1.0 ] );
594
+
// returns <Float64ArrayFE>
595
+
596
+
var out =arr.reduce( reducer );
597
+
// returns 0.0
598
+
```
599
+
600
+
The reducer function is provided four arguments:
601
+
602
+
-**acc**: accumulated result.
603
+
-**value**: current array element.
604
+
-**index**: current array element index.
605
+
-**arr**: the array on which this method was called.
606
+
607
+
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.
608
+
609
+
```javascript
610
+
functionreducer( acc, v ) {
611
+
if ( v ) {
612
+
return acc +1;
613
+
}
614
+
return acc;
615
+
}
616
+
617
+
var Float64ArrayFE =fixedEndianFactory( 'float64' );
618
+
619
+
var arr =newFloat64ArrayFE( 'little-endian', [ 1.0, 0.0, 1.0 ] );
0 commit comments