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): number

Description

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

NameTypeDescription
sortedArrnumber[]Sorted positions in pixels.
targetnumberTarget position in pixels.

Return values

The zero-based floor index, or zero for an empty array.

Example

binarySearchFloor([0, 100, 200], 150); // 1

What’s Next

Did this page help you?