Complete the code to initialize the middle index in the binary search loop.
let mid = Math.floor(([1] + high) / 2);
The middle index is calculated by averaging the low and high indices. Here, low is the correct variable to use.
Complete the code to update the low index when the target is greater than the middle element.
if (arr[mid] < target) { [1] = mid + 1; }
If the target is greater than the middle element, we move the low index to one position after mid.
Fix the error in the loop condition to correctly run the binary search.
while ([1] <= high) { let mid = Math.floor((low + high) / 2); // rest of code }
The loop should continue while low is less than or equal to high. Using mid or others is incorrect.
Fill both blanks to correctly update the high index when the target is less than the middle element.
if (arr[mid] > target) { [1] = mid [2] 1; }
When the target is less than the middle element, we move the high index to one less than mid.
Fill both blanks to return the index if the target is found, or -1 if not found.
if (arr[mid] === target) { return [1]; } // After loop return [2];
Return mid when target is found. Return -1 if not found after loop ends.