-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path121pick_temp_answer.js
More file actions
41 lines (34 loc) · 1.1 KB
/
121pick_temp_answer.js
File metadata and controls
41 lines (34 loc) · 1.1 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
function solution(answers) {
let answer = [];
let result = [];
let tempAnswer1 = [1, 2, 3, 4, 5];
let tempAnswer2 = [2, 1, 2, 3, 2, 4, 2, 5];
let tempAnswer3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
let countAnswer1 = 0;
let countAnswer2 = 0;
let countAnswer3 = 0;
let hashMap = new Map();
for (let i = 0; i < answers.length; i++) {
if (answers[i] === tempAnswer1[i % tempAnswer1.length]) {
countAnswer1 += 1;
}
if (answers[i] === tempAnswer2[i % tempAnswer2.length]) {
countAnswer2 += 1;
}
if (answers[i] === tempAnswer3[i % tempAnswer3.length]) {
countAnswer3 += 1;
}
}
answer.push(countAnswer1);
answer.push(countAnswer2);
answer.push(countAnswer3);
for (let j = 0; j < 3; j++) {
hashMap.set(j + 1, answer[j]);
}
let maxCorrectNum = Math.max(...answer);
[...hashMap.entries()].sort((a, b) => b[1] - a[1])
.map(person => {
if (person[1] === maxCorrectNum) result.push(person[0])
});
return result;
}