1function binarySearch(arr, target) {2 let left = 0;3 let right = arr.length - 1;45 while (left <= right) {6 let mid = left + ((right - left) >>> 1); // Avoid overflow and use bitwise operation78 if (arr[mid] === target) {9 return mid;10 } else if (arr[mid] < target) {11 left = mid + 1;12 } else {13 right = mid - 1;14 }15 }1617 return -1;18}1920// Test the optimized binary search function21let sortedArray = [1, 3, 5, 7, 9, 11, 13, 15, 17];2223console.log(binarySearch(sortedArray, 7)); // Should return 324console.log(binarySearch(sortedArray, 15)); // Should return 725console.log(binarySearch(sortedArray, 10)); // Should return -1 (not found)