src/modules/diff.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.13

Size

Lines of Code 41
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 23
mnd 1
bc 1
fnc 8
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
bpm 0.125
cpm 1.125
noi 0
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A Diff.compare 0 3 1
A Diff.constructor 0 5 1
A Diff.create 0 5 1
A diff.js ➔ diff 0 3 1
A Diff.differenceArray 0 6 2
A Diff.differenceArrayB 0 10 3
1
import toJson from './toJson.js';
2
3
class Diff {
4
    constructor(currentArray, otherArray, total) {
5 4
        this.currentArray = currentArray;
6 4
        this.otherArray = otherArray;
7 4
        this.total = total;
8
    }
9
10
    get differenceArray() {
11 4
        const otherArray = toJson(this.otherArray);
12 4
        return this.currentArray.filter(
13 12
            (value) => !otherArray.includes(JSON.stringify(value))
14
        );
15
    }
16
17
    get differenceArrayB() {
18 4
        if (!this.total) {
19 2
            return [];
20
        }
21 2
        const currentArray = toJson(this.currentArray);
22
23 2
        return this.otherArray.filter(
24 6
            (value) => !currentArray.includes(JSON.stringify(value))
25
        );
26
    }
27
28
    get compare() {
29 4
        return this.differenceArray.concat(this.differenceArrayB);
30
    }
31
32
    static create(currentArray, otherArray, total) {
33 4
        const differ = new Diff(currentArray, otherArray, total);
34
35 4
        return differ.compare;
36
    }
37
}
38
39
export default function diff(currentArray, otherArray, total) {
40 4
    return Diff.create(currentArray, otherArray, total);
41
}
42