코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
function solution(lottos, win_nums) {
const exceptZero = lottos.filter(number => number !== 0)
const numZero = lottos.filter(number => number ===0).length
const match = exceptZero.filter(number => win_nums.includes(number)).length
let min = 7-match >= 6 ? 6 : 7-match;
let max = min-numZero < 1 ? 1 : min-numZero;
return [max, min]
}
반응형
'알고리즘 > javascript' 카테고리의 다른 글
[프로그래머스] 코딩테스트연습 > 숫자 문자열과 영단어 (0) | 2021.09.30 |
---|---|
[프로그래머스] 코딩테스트연습 > 신규아이디 추천 (0) | 2021.09.29 |
[프로그래머스] 코딩테스트연습 > 완전탐색 > 모의고사 (0) | 2021.09.27 |
[프로그래머스] 코딩테스트연습 > 정렬 > K번째 변수 (0) | 2021.09.25 |
[프로그래머스] 코딩테스트연습 > 스택/큐 > 기능개발 (0) | 2021.09.25 |