```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 the bounds to include the upper limit
  while (low <= high) { // Adjusted the loop condition
    const mid = Math.floor((low + high) / 2);
    if (items[mid] === target) {
      return mid;
    }
    if (items[mid] < target) {
      low = mid + 1;
    } else {
      high = mid - 1; // Corrected the search direction
    }
  }
  return items.includes(target) ? mid : -1; // Handle duplicates and find the last found index if any
}
```