Created
September 1, 2018 17:23
-
-
Save Joe1220/c14f0706367b9faaeda963ada1db56fa 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
| var binarySearch = function (array, target) { | |
| var guess, min = 0, max = array.length - 1; | |
| while(min <= max) { | |
| guess = Math.floor((min + max) / 2); | |
| if(array[guess] === target) { | |
| return guess; | |
| } else if(array[guess] < target) { | |
| min = guess + 1; | |
| } else { | |
| max = guess - 1; | |
| } | |
| } | |
| return -1; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment