Skip to content
Prev Previous commit
Next Next commit
Update 220425 모의고사.js
  • Loading branch information
jaewon1676 committed Apr 25, 2022
commit 56cfd98d78027ce93a6f6cb1c802183ed000ae5b
25 changes: 25 additions & 0 deletions level-1/모의고사.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,28 @@ function solution(answers) {

return answer;
}

//정답 4 - jaewon1676
function solution(answers) {
let arr1 = [1,2,3,4,5]
let arr2 = [2,1,2,3,2,4,2,5]
let arr3 = [3,3,1,1,2,2,4,4,5,5]

let score = [0, 0, 0]
for (let i=0; i<answers.length; i++){
if (answers[i] === arr1[i%5]) {
score[0] += 1;
}
if (answers[i] === arr2[i%8]) {
score[1] += 1;
}
if (answers[i] === arr3[i%10]) {
score[2] += 1;
}
}
let answer = []
for (let i=0; i<3; i++){
if (score[i] === Math.max(...score)) answer.push(i+1)
}
return answer;
}