Skip to content

Instantly share code, notes, and snippets.

@sackeyjason
Created August 22, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sackeyjason/ba4715bc1b9115f7c5eb9cd711bb1a09 to your computer and use it in GitHub Desktop.
Save sackeyjason/ba4715bc1b9115f7c5eb9cd711bb1a09 to your computer and use it in GitHub Desktop.
Sieve of Erastosthenes
// 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