Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 23 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
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 |