sortedLastIndex

array

This method is like sortedIndex except that it returns the highest index at which value should be inserted into array in order to maintain its sort order.

Signature

sortedLastIndex<T>(array: T[], value: T): number

Parameters

NameTypeDescription
arrayT[]The sorted array to inspect
valueTThe value to evaluate

Returns

number - Returns the index at which value should be inserted into array

Examples

Find last insertion index

import { sortedLastIndex } from 'dashlite'

const result = sortedLastIndex([4, 5, 5, 5, 6], 5)
console.log(result)

Output:

4

Available since version 1.0.0