-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.js
52 lines (42 loc) · 1.31 KB
/
checks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import _ from "lodash";
import records from "./data/records.json" assert { type: "json" };
const checkDuplicates = () => {
const uniqs = _.uniqWith(records, (a, b) => _.isEqual(a.fields, b.fields));
console.log(records.length, uniqs.length, records.length - uniqs.length);
};
const turnSetToArr = (obj) => {
return Object.keys(obj).map((layer) => `${layer}:${obj[layer]}`);
};
const checkSimilar = () => {
const similars = records.reduce((acc, record) => {
const set = record.fields;
const setArr = turnSetToArr(set);
const similarToSet = records.reduce((acc, rec) => {
const intersection = _.intersection(setArr, turnSetToArr(rec.fields));
console.log(intersection, intersection.length);
return rec.id !== record.id && intersection.length >= 2
? [...acc, { set, intersection }]
: acc;
}, []);
if (_.isEmpty(similarToSet)) {
return acc;
}
return [
...acc,
{
set,
similars: similarToSet,
},
];
}, []);
console.log({ similars }, similars.length);
};
const checkSimilar2 = () => {
const similars = _.uniqWith(
records,
(a, b) =>
_.intersection(turnSetToArr(a.fields), turnSetToArr(b.fields)).length < 3
);
console.log({ similars: similars.map((s) => s.fields) }, similars.length);
};
checkSimilar2();