Skip to content

Instantly share code, notes, and snippets.

@wintercn
Last active August 25, 2023 09:30
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 wintercn/8457e8a6b58efe348cb544cd09a6d229 to your computer and use it in GitHub Desktop.
Save wintercn/8457e8a6b58efe348cb544cd09a6d229 to your computer and use it in GitHub Desktop.
JavaScript Primes
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