Skip to content

ts-ds / lowerBound

Function: lowerBound() ​

ts
function lowerBound<T>(
   array, 
   target, 
   compareFn?
): number;

Defined in: search/search.ts:41

Index of the first element that is not less than target in a sorted array — the position where target can be inserted keeping the order. Binary search: halves the range each step.

TimeMemory
O(log n)O(1)

Type Parameters ​

Type ParameterDescription
T

Parameters ​

ParameterTypeDefault valueDescription
arrayreadonly T[]undefinedArray sorted in the order of compareFn.
targetTundefinedValue to look for.
compareFn?CompareFn<T>defaultCompareOrder of the array.

Returns ​

number

From 0 to array.length.

MIT License