Skip to content

Commit 761ad25

Browse files
committed
feat: added utility for refining checks data
1 parent d3e5a16 commit 761ad25

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ScoreElement } from "../../types";
2+
import { CHECKS_LIST_NAMES } from "../../constants/checks";
3+
4+
export const getRefinedChecks = (
5+
from: ScoreElement[] = [],
6+
to: ScoreElement[] = [],
7+
) => {
8+
const haveMaxChecksNumber =
9+
from.length === CHECKS_LIST_NAMES.length &&
10+
to.length === CHECKS_LIST_NAMES.length;
11+
12+
if (haveMaxChecksNumber) {
13+
return {
14+
common: CHECKS_LIST_NAMES,
15+
discrepancies: [],
16+
};
17+
}
18+
19+
const fromNames = from.map((el: ScoreElement) => el.name);
20+
const toNames = to.map((el: ScoreElement) => el.name);
21+
const allNames = new Set([...fromNames, ...toNames]);
22+
const common = [];
23+
const discrepancies = [];
24+
25+
for (const name of allNames) {
26+
if (fromNames.includes(name) && toNames.includes(name)) {
27+
common.push(name);
28+
} else {
29+
discrepancies.push(name);
30+
}
31+
}
32+
33+
return {
34+
common: common.sort(),
35+
discrepancies: discrepancies.sort(),
36+
};
37+
};

0 commit comments

Comments
 (0)