Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Last active August 29, 2015 14:23
Show Gist options
  • Save gartenfeld/2e76cfd0cd5906618f1c to your computer and use it in GitHub Desktop.
Save gartenfeld/2e76cfd0cd5906618f1c to your computer and use it in GitHub Desktop.
The Sieve of Eratosthenes.
function Eratosthenes(max) {
var elim = {},
primes = [];
for (var i=2; i<=max; i++) {
if ( !elim[i] ) {
primes.push(i);
for (var j=i*2; j<=max; j+=i) {
elim[j] = true;
}
}
}
return primes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment