Skip to content

Commit f6c2528

Browse files
docs: add documentation for findLast method
1 parent 8fb6a86 commit f6c2528

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
@@ -908,6 +908,52 @@ var str = arr.join( 0 );
908908
// returns '10203'
909909
```
910910

911+
<a name="method-find-last"></a>
912+
913+
#### TypedArray.prototype.findLast( predicate\[, thisArg] )
914+
915+
Returns the last element in an array for which a predicate function returns a truthy value.
916+
917+
```javascript
918+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
919+
function predicate( element ) {
920+
return element < 0;
921+
}
922+
923+
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, 2.0, -4.0, 3.0 ] );
924+
925+
var res = arr.findLast( predicate );
926+
// returns -4.0
927+
```
928+
929+
The `predicate` function is provided three arguments:
930+
931+
- **value**: current array element.
932+
- **index**: current array element index.
933+
- **arr**: the array on which this method was called.
934+
935+
To set the function execution context, provide a `thisArg`
936+
937+
```javascript
938+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
939+
function predicate( v ) {
940+
this.count += 1;
941+
return ( v < 0 );
942+
}
943+
944+
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, 2.0, 3.0 ] );
945+
946+
var context = {
947+
'count': 0
948+
};
949+
950+
var z = arr.findLast( predicate, context );
951+
// returns -1.0
952+
953+
var count = context.count;
954+
// returns 3
955+
```
956+
911957
</section>
912958

913959
<!-- /.usage -->

0 commit comments

Comments
 (0)