Check out my problem at: https://github.com/harishsambasivam/SearchingAlgorithms/blob/master/BinarySearch-RecursiveMethod.js
function BinarySearch(low, high, key, arr) {
if (low > high) return 'Not Found';
if (low === high) {
if (arr[low] === key) return "Found";
else return "Not found";
} else {
var mid = Math.abs((low + high) / 2);
if (arr[mid] === key) return "Found";
else if (arr[mid] > key) return BinarySearch(low, mid - 1,
key, arr);
else return BinarySearch(mid + 1, high, key, arr);
}
}
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
console.log(BinarySearch(0, 7, 5, arr));
I expected both "found" and "not found", but only "not found" is being returned.