binarySearchFloor
Finds the last sorted position that does not exceed a target
Available since @roku-sdk/flex-grid 3.3.0
import { binarySearchFloor } from "@roku-sdk/flex-grid/geometry";Also exported as binarySearchFloor from @roku-sdk/flex-grid (deprecated).
Deprecated: binarySearchFloor. Import from @roku-sdk/flex-grid/geometry instead. The root export will be removed in the next major version.
binarySearchFloor(sortedArr: number[], target: number): numberDescription
Finds the last sorted position that does not exceed a target.
Positions must be non-decreasing. A target below the first position or an empty array returns zero. A target above the last position returns the last index. Duplicate positions select the last qualifying index.
Parameters
| Name | Type | Description |
|---|---|---|
sortedArr | number[] | Sorted positions in pixels. |
target | number | Target position in pixels. |
Return values
The zero-based floor index, or zero for an empty array.
Example
binarySearchFloor([0, 100, 200], 150); // 1Updated about 3 hours ago
What’s Next
Did this page help you?