function solution(lottos, win_nums) {
let hash = new Map();
hash.set(0, 6);
hash.set(1, 6);
hash.set(2, 5);
hash.set(3, 4);
hash.set(4, 3);
hash.set(5, 2);
hash.set(6, 1);
let 이미맞춘로또번호 = lottos.filter((num) => win_nums.includes(num)) // [];
let 최소맞춘로또번호길이 = 이미맞춘로또번호.length; // 0
let 낙서된로또 = lottos.filter((num) => num === 0); // 6
let 낙서된로또길이 = 낙서된로또.length; 6
let maxRank = hash.get(최소맞춘로또번호길이 + 낙서된로또길이);
let minRank = hash.get(최소맞춘로또번호길이);
return [maxRank, minRank];
}
function solution(lottos, win_nums) {
const rank = [6, 6, 5, 4, 3, 2, 1];
let minCount = lottos.filter(v => win_nums.includes(v)).length;
let zeroCount = lottos.filter(v => !v).length;
const maxCount = minCount + zeroCount;
return [rank[maxCount], rank[minCount]];
}
0 을 논리연산자로 적용하면 false이므로, 이 점을 이용한 풀이, 그리고 아예 rank배열을 만들어줬는데, hash보다 간단했다.