반응형
- 문제
https://school.programmers.co.kr/learn/courses/30/lessons/42840?language=javascript
- 풀이
function solution(answers) {
one = [1, 2, 3, 4, 5];
two = [2, 1, 2, 3, 2, 4, 2, 5];
three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
let countOne = 0;
let countTwo = 0;
let countThree = 0;
for (let i = 0; i < answers.length; i++) {
// 1번
if (answers[i] === one[(i % 5)])
countOne++;
// 2번
if (answers[i] === two[(i % 8)])
countTwo++;
// 3번
if (answers[i] === three[(i % 10)])
countThree++;
}
let num = Math.max(countOne, countTwo, countThree);
let result = [];
if (countOne === num) result.push(1);
if (countTwo === num) result.push(2);
if (countThree === num) result.push(3);
return result;
}
반응형
'코딩 테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스 - JavaScript] Lv.2 숫자의 표현 (0) | 2023.02.09 |
---|---|
[프로그래머스 - Python/JavaScript] Lv.1 비밀지도 (0) | 2023.02.07 |
[프로그래머스 - Python/JavaScript] Lv.1 폰켓몬 (0) | 2023.02.07 |
[프로그래머스 - Python/JavaScript] Lv.1 숫자 문자열과 영단어 (0) | 2023.02.07 |
[프로그래머스 - Python] Lv.1 다트게임 (0) | 2023.02.07 |