```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; // Change bounds to include the upper bound
  while (low <= high) { // Change condition to include equal case
    const mid = Math.floor((low + high) / 2);
    if (items[mid] === target) {
      return mid;
    }
    if (items[mid] < target) {
      low = mid + 1;
    } else {
      high = mid - 1; // Change to exclude the upper bound
    }
  }
  return items.includes(target) ? mid : -1; // Handle duplicates and absent value
}
```