Skip to content

Instantly share code, notes, and snippets.

@stmtk1
Created June 23, 2020 01:42
Show Gist options
  • Save stmtk1/d464cdac35219d13a0add5160a4e1241 to your computer and use it in GitHub Desktop.
Save stmtk1/d464cdac35219d13a0add5160a4e1241 to your computer and use it in GitHub Desktop.
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