-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurry-entries.js
65 lines (59 loc) · 1.43 KB
/
curry-entries.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
63
64
65
function defaultCurry(obj1) {
return function (obj2) {
let res = {};
for (let key in obj1) {
res[key] = obj1[key];
}
for (let key in obj2) {
res[key] = obj2[key];
}
return res;
};
}
function mapCurry(func) {
return function (obj2) {
let res = {};
for (let key in obj2) {
res[func([key, obj2[key]])[0]] = func([key, obj2[key]])[1];
}
return res;
};
}
function reduceCurry(obj1) {
return function (obj2, obj3) {
let res = obj3;
for (let key in obj2) {
res = obj1(res, [key, obj2[key]]);
}
return res;
};
}
function filterCurry(obj1) {
return function (obj2) {
let res = {};
for (let key in obj2) {
if (obj1([key, obj2[key]])) {
res[key] = obj2[key];
}
}
return res;
};
}
function reduceScore(obj1, obj2) {
return reduceCurry((acc, [, v]) =>
v.isForceUser ? acc + v.pilotingScore + v.shootingScore : acc
)(obj1, obj2);
}
function filterForce(obj) {
return filterCurry(([, v]) => v.isForceUser && v.shootingScore >= 80)(obj);
}
function mapAverage(obj) {
let avgScores = mapCurry(([k, v]) => [
k,
(v.pilotingScore + v.shootingScore) / 2,
])(obj);
for (let key in avgScores) {
obj[key].averageScore = avgScores[key];
}
return obj;
}