Skip to content

Instantly share code, notes, and snippets.

@wowdyaln
Created May 26, 2017 07:31
Show Gist options
  • Save wowdyaln/dce07a6c82d850b20698f5d3d163168e to your computer and use it in GitHub Desktop.
Save wowdyaln/dce07a6c82d850b20698f5d3d163168e to your computer and use it in GitHub Desktop.
function getPrimes(max) {
var sieve = [], i, j, primes = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime
primes.push(i);
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
}
}
}
return primes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment