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

성석민·2022년 5월 13일
1

알고리즘

목록 보기
54/72
post-thumbnail

github 전체코드

문제

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

풀이 과정

  1. 순위를 배열로 저장한다.
  2. 주어진 lottos의 배열 중 정확히 맞는 번호를 찾아낸다.
  3. 주어진 lottos의 배열 중 0의 개수를 찾아낸다.
  4. 최고 순위는 1번 배열의 (2번 + 3번)index의 값
  5. 최저 순위는 1번 배열의 (2번)index의 값
const solutionA = (lottos, win_nums) => {
  const answer = [];

  const ranks = [6, 6, 5, 4, 3, 2, 1];

  const correctCount = lottos.filter((lotto) => win_nums.includes(lotto)).length;
  const zeroCount = lottos.filter((lotto) => lotto === 0).length;

  const high = ranks[correctCount + zeroCount];
  const low = ranks[correctCount];

  answer.push(high, low);

  return answer;
};

const lottos = [44, 1, 0, 0, 31, 25];
const win_nums = [31, 10, 45, 1, 6, 19];

const testA = solutionA(lottos, win_nums);
console.log(testA);

틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄

profile
기록하는 개발자

0개의 댓글