모의고사
function solution(answers) {
let answer = [];
const personA = [1,2,3,4,5];
const personB = [2,1,2,3,2,4,2,5];
const personC = [3,3,1,1,2,2,4,4,5,5];
const aCount = getMaxCount(answers, answers.length, personA, personA.length);
const bCount = getMaxCount(answers, answers.length, personB, personB.length);
const cCount = getMaxCount(answers, answers.length, personC, personC.length);
const counts = [aCount, bCount, cCount];
const maxCount = Math.max(...counts);
counts.forEach((count, index) => {
if(count === maxCount){
answer.push(index + 1);
}
});
return answer
}
const getMaxCount = (list, listLength, personAnswers, personAnswersLength) => {
let loopCount = listLength;
let sameValue = 0;
for(let i = 0; i < loopCount; i++){
const idx = i % personAnswersLength;
if(list[i] === personAnswers[idx]){
sameValue++
}
}
return sameValue
}