Skip to content

Commit

Permalink
docs: add documentation for findLast method
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-kashkoush committed Dec 1, 2024
1 parent 8fb6a86 commit f6c2528
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,52 @@ var str = arr.join( 0 );
// returns '10203'
```

<a name="method-find-last"></a>

#### TypedArray.prototype.findLast( predicate\[, thisArg] )

Returns the last element in an array for which a predicate function returns a truthy value.

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );
function predicate( element ) {
return element < 0;
}

var arr = new Float64ArrayFE( 'little-endian', [ -1.0, 2.0, -4.0, 3.0 ] );

var res = arr.findLast( predicate );
// returns -4.0
```

The `predicate` function is provided three arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );
function predicate( v ) {
this.count += 1;
return ( v < 0 );
}

var arr = new Float64ArrayFE( 'little-endian', [ -1.0, 2.0, 3.0 ] );

var context = {
'count': 0
};

var z = arr.findLast( predicate, context );
// returns -1.0

var count = context.count;
// returns 3
```

</section>

<!-- /.usage -->
Expand Down

0 comments on commit f6c2528

Please sign in to comment.