-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path002ed2f1fd264de3b719553678a39cac_lnjv675m.js
62 lines (62 loc) · 1.68 KB
/
002ed2f1fd264de3b719553678a39cac_lnjv675m.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
53
54
55
56
57
58
59
60
61
62
let AbstractAPIHandler = require("AbstractAPIHandler");
class MyAPIHandler extends AbstractAPIHandler {
execute(request) {
let tree = request.tree;
let conditions = request.conditions;
let match = request.match;
let res = [];
// 判断是否满足条件
let judgeBranch = (branch) => {
let rst = null;
for (let i in conditions) {
let condition = conditions[i];
let kl = Object.keys(condition).length;
let n = 0;
for (let key in condition) {
for (let y in match) {
if (key === y) {
let llk = match[y];
if (branch[llk] === condition[key]) {
n++;
}
}
}
}
if (n === kl) {
rst = branch;
break;
}
}
return rst;
};
let deletetreechild = (tree) => {
let rbch = judgeBranch(tree);
if (rbch !== null) {
let childtree = rbch.children;
if (childtree !== undefined && childtree !== null) {
let newchild = [];
for (let i = 0; i < childtree.length; i++) {
let c = deletetreechild(childtree[i]);
if (c !== null) {
newchild.push(c);
}
}
if (newchild.length > 0) {
rbch.children = [];
for (let j = 0; j < newchild.length; j++) {
rbch.children[j] = newchild[j];
}
} else {
delete rbch["children"];
}
}
}
return rbch;
};
for (let i = 0; i < tree.length; i++) {
res[i] = deletetreechild(tree[i]);
}
return { res };
}
}
exports({ entryPoint: MyAPIHandler });