Skip to content

Commit d93fbf5

Browse files
committed
solution 모의고사
1 parent 4de0f8a commit d93fbf5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

level-1/모의고사.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,28 @@ function solution(answers) {
108108
if (score[i] === Math.max(...score)) answer.push(i+1)
109109
}
110110
return answer;
111+
}
112+
113+
//정답 5 - chaerin-dev
114+
function solution(answers) {
115+
const pattern = [
116+
[1, 2, 3, 4, 5],
117+
[2, 1, 2, 3, 2, 4, 2, 5],
118+
[3, 3, 1, 1, 2, 2, 4, 4, 5, 5],
119+
];
120+
const scores = [0, 0, 0];
121+
122+
answers.forEach((answer, i) => {
123+
for (let j = 0; j < pattern.length; j++) {
124+
const patternLength = pattern[j].length;
125+
if (answer === pattern[j][i % patternLength]) scores[j]++;
126+
}
127+
});
128+
129+
const answer = [];
130+
const maxScore = Math.max(...scores);
131+
scores.forEach((score, i) => {
132+
if (score === maxScore) answer.push(i + 1);
133+
});
134+
return answer;
111135
}

0 commit comments

Comments
 (0)