-
-
Save eengineergz/bc3f576b9795ccef12a108e36f9f820a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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