[알고리즘] 로또의 최고 순위와 최저 순위

김재경·2022년 3월 13일
0
function solution(lottos, win_nums) {
  const zero_count = lottos.filter((lotto) => lotto === 0).length;

  const include_nums = lottos.filter((lotto) => win_nums.includes(lotto));
  const high = include_nums.length + zero_count || 0;
  const row = include_nums.length || 0;

  const answer_obj = {
    6: 1,
    5: 2,
    4: 3,
    3: 4,
    2: 5,
  };
  const answer = [answer_obj[high] || 6, answer_obj[row] || 6];

  return answer;
}

배운점

  • filter 와 includes 의 사용 방법을 한번 더 익힘
profile
프런트앤드 개발자

0개의 댓글