src/modules/intersect.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 23
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
mnd 2
bc 2
fnc 3
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A intersect.js ➔ intersect 0 21 5
1
import toJson from './toJson.js';
2
3
export default function intersect(original, array, multi) {
4 4
    const jsonValue = toJson(array);
5 4
    const arrayLength = array.length;
6
7 4
    return original.filter((value) => {
8 12
        const valueToJson = JSON.stringify(value);
9 12
        if (multi) {
10 6
            const found = jsonValue.reduce((accumulator, currentValue) => {
11 12
                if (currentValue.includes(valueToJson)) {
12 8
                    return accumulator + 1;
13
                }
14
15 4
                return accumulator;
16
            }, 0);
17
18 6
            return found === arrayLength;
19
        }
20
21 6
        return jsonValue.includes(valueToJson);
22
    });
23
}
24