src/Helper.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 2.67

Size

Lines of Code 34
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 8
mnd 5
bc 5
fnc 3
bpm 1.6666
cpm 2.6666
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Helper.dec2bin 0 16 3
A Helper.totalTrueInputs 0 13 5
1
import InvalidInputError from './InvalidInputError';
2
3
export default class Helper {
4
    static dec2bin(number, propositions) {
5 15
        if (!Number.isInteger(number)) {
6 6
            throw new InvalidInputError(number, 'number isnt a number');
7
        }
8
9 9
        if (!Number.isInteger(propositions)) {
10 4
            throw new InvalidInputError(
11
                propositions,
12
                'propositions isnt a number'
13
            );
14
        }
15
16 5
        const binary = parseInt(number, 10).toString(2);
17
18 5
        return binary.padStart(propositions, '0');
19
    }
20
21
    static totalTrueInputs(row) {
22 133
        if (!Array.isArray(row)) {
23 4
            throw new InvalidInputError(row, 'row isnt an array');
24
        }
25
26 129
        if (row.length < 1) {
27 1
            return 0;
28
        }
29
30 128
        return row.reduce(
31 288
            (accumulator, currentValue) => accumulator + (currentValue ? 1 : 0)
32
        );
33
    }
34
}
35