Created
March 6, 2021 06:11
-
-
Save keller/bf757cc06119f8d64603c18f88ee4046 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* nums(n) { | |
yield n; | |
yield* nums(n + 1); | |
} | |
function* primes(seq) { | |
const prime = seq.next().value; | |
yield prime; | |
const nextSeq = function* () { | |
for (let num of seq) { | |
if (num % prime !== 0) yield num; | |
} | |
}; | |
yield* primes(nextSeq()); | |
} | |
let i = 0; | |
for (let n of primes(nums(2))) { | |
console.log(n); | |
if (++i >= 100) break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment