Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 05:19
Show Gist options
  • Save eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c to your computer and use it in GitHub Desktop.
Save eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c to your computer and use it in GitHub Desktop.
function binarySearch(array, target) {
if (array.length === 0) return false;
let midPt = Math.floor(array.length / 2);
if (array[midPt] === target) {
return true;
} else if (list[midPt] > target) {
return binarySearch(list.slice(0, mid), target);
} else {
return binarySearch(list.slice(midPt + 1), target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment