Skip to main content

모의고사

Solution

function solution(answers) {
// 각 사람 찍기 패턴
const { firstPattern, secondPattern, thirdPattern } = {
firstPattern: [1, 2, 3, 4, 5],
secondPattern: [2, 1, 2, 3, 2, 4, 2, 5],
thirdPattern: [3, 3, 1, 1, 2, 2, 4, 4, 5, 5],
};

// 종합할 변수 정의
const scoreList = Array(3).fill(0);

// 각 사람 채점
answers.forEach((answer, idx) => {
if (answer === firstPattern[idx % firstPattern.length]) scoreList[0] += 1;
if (answer === secondPattern[idx % secondPattern.length]) scoreList[1] += 1;
if (answer === thirdPattern[idx % thirdPattern.length]) scoreList[2] += 1;
});

// 1등 점수 구한 뒤 누가 일등인지 판별
const topScore = Math.max(...scoreList);
return scoreList.reduce((acc, curScore, idx) => {
if (curScore === topScore) acc.push(idx + 1);

return acc;
}, []);
}

Review

.

References