```ts
export function binarySearch(items: readonly number[], target: number): number {
  let low = 0;
  let high = items.length - 1;
  while (low <= high) { // added this line to include the last element if the value is exactly equal
    const mid = Math.floor((low + high) / 2);
    if (items[mid] === target) {
      return mid;
    }
    if (items[mid] < target) {
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return -(items.length - low); // if low exceeds length, high will hit its ceiling and it gives the next index which will have value as expected.
}
```