Passed
Push — main ( 12d9ec...5a557a )
by Dylan
04:52
created

src/bigint.ts   A

Complexity

Total Complexity 12
Complexity/F 12

Size

Lines of Code 35
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
eloc 18
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
mnd 11
bc 11
fnc 1
bpm 11
cpm 12
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C bigint.ts ➔ primes 0 8 9
1
/**
2
 * Find the greatest common denominator of the two numbers.
3
 */
4 5
export const gcd = (a: bigint, b: bigint): bigint => {
5 244
  if (b === 1n || a === 1n) {
6 124
    return 1n
7
  }
8 120
  while (b !== 0n) {
9 2847
    [a, b] = [b, a % b]
10
  }
11 120
  return a < 0n ? -a : a
12
}
13
14
/**
15
 * Returns true if the number is prime.
16
 */
17 5
export const isPrime = (n: bigint): boolean => {
18 16
  if (n === 1n) return false
19 15
  for (let i = 2n; i*i <= n; i++) {
20 100
    if (n%i === 0n) return false
21
  }
22 8
  return true
23
}
24
25
/**
26
 * Yields the prime numbers.
27
 */
28 5
export function* primes(): Generator<bigint> {
29 1
  for (let n = 2n; true; n++) {
30 10
    if (isPrime(n)) {
31 5
      yield n
32
    }
33
  }
34
}
35