Skip to content

Instantly share code, notes, and snippets.

@andersonFaro9
Created March 13, 2024 19:44
Show Gist options
  • Save andersonFaro9/95fd77ba60bbe0c58f2d5fea0b83fd86 to your computer and use it in GitHub Desktop.
Save andersonFaro9/95fd77ba60bbe0c58f2d5fea0b83fd86 to your computer and use it in GitHub Desktop.
function searchBinary(arrays, item) {
let baixo = 1
let alto = (arrays - 1)
if(baixo <= alto) {
let meio = (baixo + alto)/ 2
let chute = arrays[meio]
if (chute == item) {
return meio
}
if(chute > item) {
alto = (meio - 1)
}
else {
baixo = (meio + 1)
}
return null
}
const numbers = [1,3,5,6,7,8,11]
console.log("resultado:",searchBinary(numbers, 3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment