function
recursiveBS(arr, target, left, right) {
if
(left > right)
return
-1;
mid = Math.floor((left + right) / 2);
if
(arr[mid] === target)
return
mid;
else
if
(arr[mid] > target) {
return
recursiveBS(arr, target, left, mid - 1);
}
else
{
return
recursiveBS(arr, target, mid + 1, right);
}
return
-1;
}
arr = [1, 2, 6, 7, 11, 13, 15, 18];
target = 7;
index = recursiveBS(arr, target, 0, arr.length - 1);
if
(index == -1)
console.log(
target +
" is not present in the given array"
);
else
console.log(target +
" is present at index: "
+ index);