blob: 6a6df629cef12e5297f6ce46b33a0f0444dc8244 (
plain)
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
|
export function getBranchRequierds(node, requiredArr) {
if (node.parent) {
if (node.parent.data.hasOwnProperty('requiredChildren')) {
requiredArr.push(node.parent.data.requiredChildren);
}
return getBranchRequierds(node.parent, requiredArr);
}
return requiredArr;
}
export function validation(node, userSelection) {
const requiredArr = [];
const validationRequired = getBranchRequierds(node, requiredArr);
const nonValidationArr = [];
validationRequired.forEach(nodeRequireds => {
return nodeRequireds.forEach(levelRequired => {
if (userSelection.filter(node => node === levelRequired).length === 0) {
nonValidationArr.push(levelRequired);
}
return;
});
});
return nonValidationArr;
}
export function fuzzysearch(needle, haystack) {
const haystackLC = haystack.toLowerCase();
const needleLC = needle.toLowerCase();
const hlen = haystack.length;
const nlen = needleLC.length;
if (nlen > hlen) {
return false;
}
if (nlen === hlen) {
return needleLC === haystackLC;
}
outer: for (let i = 0, j = 0; i < nlen; i++) {
const nch = needleLC.charCodeAt(i);
while (j < hlen) {
if (haystackLC.charCodeAt(j++) === nch) {
continue outer;
}
}
return false;
}
return true;
}
|