Level1 - 로또의 최고 순위와 최저 순위

손대중·2022년 3월 10일
0

문제 설명 및 링크

프로그래머스 - 로또의 최고 순위와 최저 순위

나의 풀이

  • 내가 받을 수 있는 최고 순위
    • "0 이 아닌 숫자 중 당첨 번호와 동일한 숫자 개수" + "0 의 개수"
  • 내가 받을 수 있는 최저 순위
    • "0 이 아닌 숫자 중 당첨 번호와 동일한 숫자 개수"

코드

모든 프로그래머스 문제 관련 코드들은 GitHub 링크 에 있음.

function solution(lottos, win_nums) {
    var answer = [];
    
    const rightLength = lottos.filter(l => win_nums.includes(l)).length;
    const zeroLength = lottos.filter(l => l === 0).length;
    
    const getLank = length => {
        let rank = 7 - length;
        if (rank >= 6) {
            rank = 6;
        }
        return rank;
    };
    
    answer.push(getLank(rightLength + zeroLength));
    answer.push(getLank(rightLength));
    
    return answer;
}

0개의 댓글