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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”readonly T[]
Array sorted ascending by valueOf. Must be non-empty.
number
The key to find the closest element to.
valueOf
Section titled “valueOf”Callable<[T], number>
Extracts the numeric sort key from an item.
Returns
Section titled “Returns”number
The index of the closest element.