Skip to content

Instantly share code, notes, and snippets.

@NoxWings
Last active September 12, 2019 14:38
Show Gist options
  • Save NoxWings/747855e5ac0aeb6b2b984480d2c83ae5 to your computer and use it in GitHub Desktop.
Save NoxWings/747855e5ac0aeb6b2b984480d2c83ae5 to your computer and use it in GitHub Desktop.
const range = (min, max) => Array(max - min).fill().map((_, i) => i + min);
function fastPrimes(n) {
var p = range(2, n);
for (var i = 0; i < p.length; i++) {
for (var j = i + p[i]; j < p.length; j += p[i]) { p[j] = undefined; }
p = p.filter(n => n);
}
return p;
}
console.log(JSON.stringify(fastPrimes(1000)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment