MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / primes

Function primes

code/solutions/22_1_prime_numbers.js:1–12  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1function* primes() {
2 for (let n = 2;; n++) {
3 let skip = false;
4 for (let d = 2; d < n; d++) {
5 if (n % d == 0) {
6 skip = true;
7 break;
8 }
9 }
10 if (!skip) yield n;
11 }
12}
13
14function measurePrimes() {
15 let iter = primes(), t0 = Date.now();

Callers 1

measurePrimesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected