Skip to content

Instantly share code, notes, and snippets.

@jsatk
Last active December 12, 2015 10:08
Show Gist options
  • Save jsatk/4756665 to your computer and use it in GitHub Desktop.
Save jsatk/4756665 to your computer and use it in GitHub Desktop.
// [Sieve of Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
var getPrimes = function (max) {
"use strict";
var sieve = [],
primes = [];
for (var i = 2; i <= max; i += 1) {
if (!sieve[i]) {
primes.push(i);
for (var 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