Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Last active December 27, 2015 04:49
Show Gist options
  • Save prettymuchbryce/7270047 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/7270047 to your computer and use it in GitHub Desktop.
//Sieve of Eratosthenes
function findPrimesUpTo(value) {
var primes = [];
primes.push(false,false);
for (var i = 2; i < value; i++) {
primes.push(true);
}
for (var i = 2; i < Math.sqrt(value); i++) {
if (primes[i] == true) {
for (var j = Math.pow(i,2); j < value; j+=i) {
primes[j] = false;
}
}
}
return primes;
}
console.log(findPrimesUpTo(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment