[javascript] Programmers 완전탐색 level1 모의고사

j·2021년 8월 16일
0

알고리즘

목록 보기
3/4

문제

[Programmers] 완전탐색 level1 모의고사

체크 포인트

각 수포자가 찍는 패턴 👉전체👈를 변수에 저장

풀이

function solution(answers) {
    const result = [];
    const supoPointArray = [0, 0, 0];
    const supo1Pattern = [1, 2, 3, 4, 5];
    const supo2Pattern = [2, 1, 2, 3, 2, 4, 2, 5];
    const supo3Pattern = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
    
    answers.forEach((answer, answerIdx) => {
        if (answer === supo1Pattern[answerIdx % 5]) {
            supoPointArray[0] += 1;
        }
        if (answer === supo2Pattern[answerIdx % 8]) {
            supoPointArray[1] += 1;
        }
        if (answer === supo3Pattern[answerIdx % 10]) {
            supoPointArray[2] += 1;
        }
    });
    
    const maxPoint = Math.max(...supoPointArray);
    
    supoPointArray.forEach((point, index) => {
        if (maxPoint === point) {
            result.push(index + 1);
        }
    });
    
    return result.sort((x, y) => x - y);
}



디버깅

각 수포자 케이스를 다르게 생각했고, 각각의 경우를 따로따로 처리하다보니 오류가 생성된듯 하다

(원인 파악 후 처리 예정)

profile
같은 실수를 하지 않기 위해 기록을 남깁니다

0개의 댓글

관련 채용 정보