가오리의 코딩일기

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

HTML+CSS+JavaScript/프로그래머스

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

류경혜 2022. 6. 10. 13:00

https://programmers.co.kr/learn/courses/30/lessons/77484

 

코딩테스트 연습 - 로또의 최고 순위와 최저 순위

로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호

programmers.co.kr

function solution(lottos, win_nums) {
  const correct = lottos.filter((lotto) => win_nums.includes(lotto)).length;
  const zeros = lottos.filter((lotto) => lotto === 0).length;
  console.log(correct, zeros);
  let min = 7 - correct >= 6 ? 6 : 7 - correct;
  let max = min - zeros < 1 ? 1 : min - zeros;
  return [max, min];
}

'HTML+CSS+JavaScript > 프로그래머스' 카테고리의 다른 글

[76501] 음양 더하기  (0) 2022.06.13
제일 작은 수 제거하기  (0) 2022.06.13
완주하지 못한 선수  (0) 2022.06.10
두개 뽑아서 더하기  (0) 2022.06.09
K번째수  (0) 2022.06.09