Last active
August 25, 2023 09:30
-
-
Save wintercn/8457e8a6b58efe348cb544cd09a6d229 to your computer and use it in GitHub Desktop.
JavaScript Primes
This file contains hidden or 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(){ | |
let primes = []; | |
let i = 1; | |
outer:while(true) { | |
++ i; | |
for(let p of primes) | |
if(p % i === 0) | |
continue outer; | |
primes.push(i); | |
yield i; | |
} | |
} | |
for(let p of primes(100)) { | |
console.log(p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment