Last active
March 12, 2023 01:54
-
-
Save wlib/d05580799263664731af42f37eb2e934 to your computer and use it in GitHub Desktop.
Javascript prime number generator function
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
function * primes(max = 1_000) { | |
const isComposite = [] | |
for (let i = 2; i <= max; i++) if (!isComposite[i]) { | |
yield i | |
for (let j = i**2; j <= max; j += i) | |
isComposite[j] = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment