```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; // Changed from high to items.length to include the last element
  while (low < high) { // Ensure low is always less than or equal to high
    const mid = Math.floor((low + high) / 2);
    if (items[mid] === target) {
      return mid;
    }
    if (items[mid] < target) {
      low = mid + 1; // Move the lower bound up to mid + 1
    } else {
      high = mid; // Move the upper bound down to mid
    }
  }
  return -1;
}
```