Created
August 22, 2020 10:58
-
-
Save sackeyjason/ba4715bc1b9115f7c5eb9cd711bb1a09 to your computer and use it in GitHub Desktop.
Sieve of Erastosthenes
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
// List the first n prime numbers | |
primes = n => { | |
const results = [] | |
let i = 1 | |
while (results.length < n) { | |
++i | |
results.find(r => i % r === 0) || results.push(i) | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment