-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod.js
More file actions
78 lines (71 loc) · 2.19 KB
/
method.js
File metadata and controls
78 lines (71 loc) · 2.19 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
function method(options, ranks) {
const optionsList = options;
const rows = ranks;
const d = [];
const p = [];
optionsList.forEach((option1) => {
d[option1] = [];
optionsList.forEach((option2) => {
d[option1][option2] = 0;
});
});
optionsList.forEach((option1) => {
p[option1] = [];
optionsList.forEach((option2) => {
p[option1][option2] = 0;
});
});
rows.forEach((row) => {
d[row.Option1][row.Option2] = parseInt(row.K, 10);
});
for (let i = 0; i < optionsList.length; i += 1) {
for (let j = 0; j < optionsList.length; j += 1) {
if (i !== j) {
if (d[optionsList[i]][optionsList[j]] > d[optionsList[j]][optionsList[i]]) {
p[optionsList[i]][optionsList[j]] = d[optionsList[i]][optionsList[j]];
} else {
p[optionsList[i]][optionsList[j]] = 0;
}
}
}
}
for (let i = 0; i < optionsList.length; i += 1) {
for (let j = 0; j < optionsList.length; j += 1) {
if (i !== j) {
for (let k = 0; k < optionsList.length; k += 1) {
if (i !== k && j !== k) {
p[optionsList[j]][optionsList[k]] = Math.max(
p[optionsList[j]][optionsList[k]],
Math.min(
p[optionsList[j]][optionsList[i]],
p[optionsList[i]][optionsList[k]],
),
);
}
}
}
}
}
const optionsMarks = [];
for (let i = 0; i < optionsList.length; i += 1) {
optionsMarks[optionsList[i]] = 0;
for (let j = 0; j < optionsList.length; j += 1) {
if (p[optionsList[i]][optionsList[j]] > p[optionsList[j]][optionsList[i]]) {
optionsMarks[optionsList[i]] += 2;
} else if (p[optionsList[i]][optionsList[j]] > p[optionsList[j]][optionsList[i]]) {
optionsMarks[optionsList[i]] += 1;
}
}
}
const optionsRating = optionsList.map((option) => {
const result = {
id: option,
mark: optionsMarks[option],
place: optionsMarks.filter((item) => (item > optionsMarks[option])).length,
count: optionsMarks.filter((item) => (item === optionsMarks[option])).length,
};
return result;
});
return optionsRating;
}
module.exports = { method };