sortedIndexBy

array

This method is like sortedIndex except that it accepts iteratee which is invoked for value and each element of array to compute their sort ranking.

Signature

sortedIndexBy<T, U>(array: T[], value: T, iteratee: (value: T) => U): number

Parameters

NameTypeDescription
arrayT[]The sorted array to inspect
valueTThe value to evaluate
iteratee(value: T) => UThe iteratee invoked per element

Returns

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

Examples

With iteratee

import { sortedIndexBy } from 'dashlite'

const objects = [{ x: 4 }, { x: 5 }]
const result = sortedIndexBy(objects, { x: 4 }, (o) => o.x)
console.log(result)

Output:

0

Available since version 1.0.0