Completed
Push — master ( 33fc28...734acd )
by Pieter Epeüs
11s queued 10s
created

Diff   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 33
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A differenceArrayB 0 9 3
A compare 0 3 1
A constructor 0 5 1
A differenceArray 0 5 2
A create 0 5 1
1
class Diff {
2
    constructor(currentArray, otherArray, total) {
3
        this.currentArray = currentArray;
4
        this.otherArray = otherArray;
5
        this.total = total;
6
    }
7
8
    get differenceArray() {
9
        return this.currentArray.filter(
10
            (value) => this.otherArray.indexOf(value) < 0
11
        );
12
    }
13
14
    get differenceArrayB() {
15
        if (!this.total) {
16
            return [];
17
        }
18
19
        return this.otherArray.filter(
20
            (value) => this.currentArray.indexOf(value) < 0
21
        );
22
    }
23
24
    get compare() {
25
        return this.differenceArray.concat(this.differenceArrayB);
26
    }
27
28
    static create(currentArray, otherArray, total) {
29
        const diff = new Diff(currentArray, otherArray, total);
30
31
        return diff.compare;
32
    }
33
}
34
35
module.exports = function diff(currentArray, otherArray, total) {
36
    return Diff.create(currentArray, otherArray, total);
37
};
38