Skip to content

bisectCenter

bisectCenter<T>(items, value, valueOf): number

Defined in: ordered/bisect-center.ts:20

Finds the index of the element in items whose key is closest to value.

Takes a numeric key accessor rather than a comparator: “nearest” is a metric question, and a comparator only reports which side an element falls on, never how far away it is. Ties resolve to the right-hand neighbour.

O(log n). valueOf must return finite, non-NaN keys — NaN has no magnitude, so a distance derived from one is meaningless.

T

readonly T[]

Array sorted ascending by valueOf. Must be non-empty.

number

The key to find the closest element to.

Callable<[T], number>

Extracts the numeric sort key from an item.

number

The index of the closest element.