sortedLastIndexOf
arrayThis method is like lastIndexOf except that it performs a binary search on a sorted array.
Signature
sortedLastIndexOf<T>(array: T[], value: T): numberParameters
| Name | Type | Description |
|---|---|---|
array | T[] | The sorted array to inspect |
value | T | The value to search for |
Returns
number - Returns the index of the matched value, else -1
Examples
Binary search from end
import { sortedLastIndexOf } from 'dashlite'
const result = sortedLastIndexOf([4, 5, 5, 5, 6], 5)
console.log(result)Output:
3Available since version 1.0.0