Created
June 23, 2020 01:42
-
-
Save stmtk1/d464cdac35219d13a0add5160a4e1241 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
function* primes(n) { | |
const container = [] | |
yield 2; | |
container.push(2); | |
for(let i = 3; i <= n; i += 2) { | |
let is_prime = true; | |
for(p of container) { | |
if(i % p == 0) { | |
is_prime = false; | |
break; | |
} | |
} | |
if(is_prime) { | |
container.push(i); | |
yield i; | |
} | |
} | |
} | |
for(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