Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xotic750/find-last-index-x
Search an array from the end and return the matched index.
https://github.com/xotic750/find-last-index-x
array browser ecmascript nodejs
Last synced: 4 days ago
JSON representation
Search an array from the end and return the matched index.
- Host: GitHub
- URL: https://github.com/xotic750/find-last-index-x
- Owner: Xotic750
- License: mit
- Created: 2015-11-26T15:51:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-31T10:51:39.000Z (almost 5 years ago)
- Last Synced: 2024-12-17T16:52:42.403Z (about 1 month ago)
- Topics: array, browser, ecmascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 3.22 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## find-last-index-x
Search an array from the end and return the matched index.
### `module.exports(array, callback, [thisArg])` ⇒
number
⏏Like `findIndex`, this method returns an index in the array, if an element
in the array satisfies the provided testing function, except it is peformed
in reverse. Otherwise -1 is returned.**Kind**: Exported function
**Returns**:number
- Returns index of positively tested element, otherwise -1.
**Throws**:-
TypeError
If array is `null` or `undefined`-
-TypeError
If `callback` is not a function.| Param | Type | Description |
| --------- | --------------------- | ------------------------------------------------------------------------------------------------------- |
| array |Array
| The array to search. |
| callback |function
| Function to execute on each value in the array, taking three arguments: `element`, `index` and `array`. |
| [thisArg] |\*
| Object to use as `this` when executing `callback`. |**Example**
```js
import findLastIndex from 'find-index-x';function isPrime(element, index, array) {
var start = 2;
while (start <= Math.sqrt(element)) {
if (element % start++ < 1) {
return false;
}
}
return element > 1;
}console.log(findLastIndex([4, 6, 8, 12, 14], isPrime)); // -1, not found
console.log(findLastIndex([4, 6, 7, 12, 13], isPrime)); // 4
```