Skip to content

Instantly share code, notes, and snippets.

@osha7
Last active February 20, 2021 20:05
Show Gist options
  • Save osha7/a2ef65262e36e77dd655c24b34f5349a to your computer and use it in GitHub Desktop.
Save osha7/a2ef65262e36e77dd655c24b34f5349a to your computer and use it in GitHub Desktop.
let arr = [1, 5, 14, 23, 27, 32, 40, 54, 59, 67, 73]
let target = 54
let binarySearchFunction = function(arr, target) {
let leftPointer = 0
let rightPointer = arr.length - 1
while (leftPointer <= rightPointer) {
let med = Math.ceil((rightPointer + leftPointer) / 2)
if (arr[med] === target) return med
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment