let arr = [
1,
2,
3,
4,
5,
6,
7,
8,
9
];
function search(list, item) {
let low = 0;
let high = arr.length - 1;
while (low <= high) {
let mid = Math.floor((low + high) / 2);
let guess = list[mid];
if (guess === item) {
return mid;
} else if (guess > mid) {
high = mid - 1;
} else if (guess < mid) {
low = mid + 1;
}
}
return undefined;
}
console.log(search(arr, 3));