/**
* 로또의 최고 순위와 최저 순위
* https://programmers.co.kr/learn/courses/30/lessons/77484
*/
function solution(lottos, win_nums) {
let min = 7, max = 7, match = 0;
const joker = lottos.reduce((acc, num) => {
if (num === 0) acc++;
return acc;
} , 0);
const lottosWithoutJoker = lottos.filter((num) => num !== 0);
lottosWithoutJoker.forEach((num) => {
if (win_nums.some((winNum) => winNum === num)) match++
});
return [Math.min(max - match - joker, 6), Math.min(min - match, 6)];
}
console.log(solution([44, 1, 0, 0, 31, 25], [31, 10, 45, 1, 6, 19]));
console.log(solution([0, 0, 0, 0, 0, 0], [38, 19, 20, 40, 15, 25]));
console.log(solution([45, 4, 35, 20, 3, 9], [20, 9, 3, 45, 4, 35]));
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][자바스크립트][Level2] 카펫 (0) | 2022.01.03 |
---|---|
[프로그래머스][자바스크립트][Level1][카카오] 숫자 문자열과 영단어 (0) | 2022.01.02 |
[프로그래머스][자바스크립트][Level1] 부족한 금액 계산하기 (0) | 2021.08.05 |
[프로그래머스][자바스크립트][Level2][카카오] 오픈채팅방 (0) | 2021.07.22 |
[프로그래머스][자바스크립트][Level2][카카오] 문자열 압축 (0) | 2021.07.22 |
댓글