Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 04:59
Show Gist options
  • Save eengineergz/bc3f576b9795ccef12a108e36f9f820a to your computer and use it in GitHub Desktop.
Save eengineergz/bc3f576b9795ccef12a108e36f9f820a to your computer and use it in GitHub Desktop.
function binarySearch(arr, x, start, end) {
if (start > end) return false;
let mid = Math.floor((start + end) / 2);
if (arr[mid] === x) return true;
if (arr[mid] > x) {
return binarySearch(arr, x, start, mid - 1);
} else {
return binarySearch(arr, x, mid + 1, end);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment