```typescript
/** The index of target in a sorted array, or -1 if not found. */
export function binarySearch(items: readonly number[], target: number): number {
  let low = 0;
  let high = items.length;

  while (low < high) {
    const mid = Math.floor((low + high) / 2);

    if (items[mid] === target) {
      return mid; // Return the index of the match
    }
    if (items[mid] < target) {
      low = mid + 1; // Search in the right half
    } else {
      high = mid; // Search in the left half
    }
  }

  return -1; // Target not found
}
```