1 const binarySearch = (arr, key) => { 2 let low = 0, high = arr.length - 1; 3 while(low <= high){ 4 let mid = Math.floor((low + high) / 2) 5 let guess = arr[mid] 6 if(guess === key){ 7 return mid 8 } 9 if(guess > key){ 10 high = mid - 1 11 }else{ 12 low = mid + 1 13 } 14 } 15 return -1 16 }