Skip to main content
Module

x/structurae/index.ts>SortedArray.getIndex

Data structures for high-performance JavaScript applications.
Latest
method SortedArray.getIndex
import { SortedArray } from "https://deno.land/x/structurae@4.0.1/index.ts";

Uses binary search to find the index of an element inside a sorted array.

Examples

SortedArray.getIndex([1, 2, 3, 4, 8], 4); //=> 3

Parameters

arr: U

the array to search

target: T

the target value to search for

optional
comparator: Comparator<T> = [UNSUPPORTED]
optional
rank = [UNSUPPORTED]
optional
start = [UNSUPPORTED]
optional
end = [UNSUPPORTED]

Returns

number

the index of the searched element or it's rank