findNearestSortedIndex
Finds the sorted position nearest to a target within a prefix
Available since @roku-sdk/flex-grid 3.3.0
import { findNearestSortedIndex } from "@roku-sdk/flex-grid/geometry";Also exported as findNearestSortedIndex from @roku-sdk/flex-grid (deprecated).
Deprecated: findNearestSortedIndex. Import from @roku-sdk/flex-grid/geometry instead. The root export will be removed in the next major version.
findNearestSortedIndex(positions: number[], count: number, target: number): numberDescription
Finds the sorted position nearest to a target within a prefix.
Positions must be non-decreasing in the searched prefix. The count is capped at the array length. An empty prefix or a count of one returns zero. Targets outside the prefix select its nearest endpoint; equal-distance ties select the lower index.
Parameters
| Name | Type | Description |
|---|---|---|
positions | number[] | Sorted positions in pixels. |
count | number | Number of positions to search, as a non-negative integer. |
target | number | Target position in pixels. |
Return values
The zero-based nearest index, or zero for an empty prefix.
Example
findNearestSortedIndex([0, 100, 200], 3, 160); // 2Updated about 5 hours ago
What’s Next
Did this page help you?