https://programmers.co.kr/learn/courses/30/lessons/77484#fnref1
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
const hitToRank = {
6: 1,
5: 2,
4: 3,
3: 4,
2: 5,
1: 6,
0: 6
}
function solution(lottos, win_nums) {
const undefinedNumber = lottos.filter(num=>num===0).length;
const hitCount = win_nums.filter(num=>lottos.includes(num)).length;
return [hitToRank[undefinedNumber + hitCount], hitToRank[hitCount]];
}
728x90
'Basic > Algorithm' 카테고리의 다른 글
숫자 문자열과 영단어 (0) | 2021.08.13 |
---|---|
비밀지도 (0) | 2021.08.13 |
다트 게임 (2) | 2021.08.04 |
댓글