Last active
October 26, 2015 03:26
-
-
Save jdetle/06db7927356e60a87176 to your computer and use it in GitHub Desktop.
This file contains 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
//numPrimes is above in scope, array that maps bin to the number of primes up to it | |
//takes n of the prime that we are looking for | |
//returns bin | |
function binSearch(target, bins){ | |
lastBin = bins[bins.size-1]; | |
if(target < numPrimes[lastBin] && target > numPrimes[lastBin-1]){ | |
return lastBin; | |
} | |
else if(target < numPrimes[lastBin]){ | |
return binSearch(target,bins.slice(0,bins.size/2)); | |
} | |
else{ | |
return binSearch(target,bins.slice(bins.size/2+1,bins.size)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment