Skip to content

Instantly share code, notes, and snippets.

@jdetle
Last active October 26, 2015 03:26
Show Gist options
  • Save jdetle/06db7927356e60a87176 to your computer and use it in GitHub Desktop.
Save jdetle/06db7927356e60a87176 to your computer and use it in GitHub Desktop.
//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