collatz-conjecture/collatz-conjecture.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 13
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
mnd 3
bc 3
fnc 2
dl 0
loc 13
rs 10
bpm 1.5
cpm 2.5
noi 0
c 0
b 0
f 0
1
const collatz = (n) => {
2
  if (n === 1) {
3
    return 0;
4
  }
5
  return collatz(n % 2 === 0 ? n / 2 : n * 3 + 1) + 1;
6
};
7
8
export const steps = (n) => {
9
  if (n < 1) {
10
    throw new Error('Only positive numbers are allowed');
11
  }
12
  return collatz(n);
13
};
14