```typescript
/** The index of target in a sorted array, or -1. */
export function binarySearch(items: readonly number[], target: number): number {
  let low = 0;
  let high = items.length - 1; // FIXED: changed the upper bound
  while (low <= high && low < items.length) { // FIXED: made it inclusive and checked bounds
    const mid = Math.floor((low + high) / 2);
    if (items[mid] === target) {
      return mid;
    }
    if (items[mid] < target) {
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  // FIXED: added condition for not found value
  if (low >= items.length || items[low] !== target) {
    return -1;
  }
  return low; // RETURNED the found index instead of just low when it's correct
}
```