Complete the code to find the middle index in binary search.
let mid = (low + [1]) / 2;
In binary search, the middle index is calculated by averaging the low and high indices.
Complete the code to compare the middle element with the target.
if arr[mid] [1] target {
We check if the middle element equals the target to find the item.
Fix the error in updating the low index when target is greater than middle element.
if arr[mid] < target { low = [1]; }
We move low to mid + 1 to search the right half excluding mid.
Fill both blanks to update high index when target is less than middle element.
if arr[mid] > target { [1] = [2]; }
We set high to mid - 1 to search the left half excluding mid.
Fill all three blanks to complete the binary search loop condition and return statement.
while [1] <= [2] { let mid = (low + high) / 2; if arr[mid] == target { return [3]; } // update low or high }
The loop runs while low is less or equal to high. Return mid when found.
