Created
March 13, 2024 19:44
-
-
Save andersonFaro9/95fd77ba60bbe0c58f2d5fea0b83fd86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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