function recursive_binary_search(arr: number[], left: number, right: number, to_find: number) {
if (right >= left) {
let mid: number = Math.ceil(left + (right - left) / 2);
if (arr[mid] === to_find)
return mid;
if (arr[mid] > to_find)
return recursive_binary_search(arr, left, mid - 1, to_find);
return recursive_binary_search(arr, mid + 1, right, to_find);
}
return -1;
}
const arr: number[] = new Array(2, 3, 6, 7, 12, 13, 17, 19, 21, 28);
const to_find: number = 13;
const i: number = recursive_binary_search(arr, 0, arr.length - 1, to_find);
(i === -1) ? console.log("not found") : console.log("Found at index: " + i);
/*
run:
"Found at index: 5"
*/