Skip to content

Commit affacb7

Browse files
committed
feat: readme added
1 parent 2ee065b commit affacb7

File tree

1 file changed

+46
-0
lines changed
  • lib/node_modules/@stdlib/array/fixed-endian-factory

1 file changed

+46
-0
lines changed

lib/node_modules/@stdlib/array/fixed-endian-factory/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,52 @@ var count = context.count;
577577
// returns 3;
578578
```
579579

580+
<a name="method-reduce"></a>
581+
582+
#### TypedArray.prototype.reduce( reducerFn\[, initialValue] )
583+
584+
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+
function reducer( acc, v ) {
588+
return ( acc && v );
589+
}
590+
591+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
592+
593+
var arr = new Float64ArrayFE( '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+
function reducer( acc, v ) {
611+
if ( v ) {
612+
return acc + 1;
613+
}
614+
return acc;
615+
}
616+
617+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
618+
619+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 0.0, 1.0 ] );
620+
// returns <Float64ArrayFE>
621+
622+
var out = arr.reduce( reducer, 0 );
623+
// returns 2
624+
```
625+
580626
<a name="method-set"></a>
581627

582628
#### TypedArrayFE.prototype.set( arr\[, offset] )

0 commit comments

Comments
 (0)