sortedIndex
arrayUses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order.
Signature
sortedIndex<T>(array: T[], value: T): numberParameters
| Name | Type | Description |
|---|---|---|
array | T[] | The sorted array to inspect |
value | T | The value to evaluate |
Returns
number - Returns the index at which value should be inserted into array
Examples
Find insertion index
import { sortedIndex } from 'dashlite'
const result = sortedIndex([30, 50], 40)
console.log(result)Output:
1Available since version 1.0.0