링크
참고
나의 풀이
function solution(answers) {
let result = [];
let bestStudent = [];
let student1 = [1, 2, 3, 4, 5];
let student2 = [2, 1, 2, 3, 2, 4, 2, 5];
let student3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
student1 = new Array(answers.length).fill([1, 2, 3, 4, 5]).flat();
student2 = new Array(answers.length).fill([2, 1, 2, 3, 2, 4, 2, 5]).flat();
student3 = new Array(answers.length).fill([3, 3, 1, 1, 2, 2, 4, 4, 5, 5]).flat();
const correctStudent1 = student1.filter((student, index) => {
return student === answers[index];
});
const correctStudent2 = student2.filter((student, index) => {
return student === answers[index];
});
const correctStudent3 = student3.filter((student, index) => {
return student === answers[index];
});
const lenStudent1 = correctStudent1.length;
const lenStudent2 = correctStudent2.length;
const lenStudent3 = correctStudent3.length;
result.push(lenStudent1, lenStudent2, lenStudent3);
const bestScores = result.filter((num, index) => {
return num === Math.max(...result);
});
for (let i = 0; i < result.length; i++) {
if (result[i] === bestScores[0]) {
bestStudent.push(i + 1);
}
}
return bestStudent.sort((a, b) => a - b);
}
... 더 좋은 방법이 없을까...?