Last active
September 12, 2019 14:38
-
-
Save NoxWings/747855e5ac0aeb6b2b984480d2c83ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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