Write binarySearch(sorted, target). sorted is an array of numbers in ascending order with no duplicates, for example the pixel offsets at which each row of a virtualised list starts. Return the index of target, or -1 if it isn't present.
const rowOffsets = [0, 48, 96, 160, 208, 300];
binarySearch(rowOffsets, 160); // 3
binarySearch(rowOffsets, 0); // 0
binarySearch(rowOffsets, 170); // -1
binarySearch([], 5); // -1
indexOf, includes or findIndex.≥ target (useful for "which row is at scroll position 170?")?Spotted a mistake or a rights concern? Report an issue