프로그래머스 77484
// 개수를 구하는 함수
const getCount = (...args) => {
if(args.length === 2) {
return args[0].filter( n => args[1].includes(n)).length;
} else {
return args[0].filter( n => n === 0).length;
}
}
function solution(lottos, win_nums) {
const rank = [6,6,5,4,3,2,1];
const zeroCnt = getCount(lottos);
if(zeroCnt === 6) return [1,6];
const worst = getCount(lottos, win_nums);
if(worst === 6) return [1,1];
return [rank[worst+zeroCnt], rank[worst]]
}
function solution(lottos, win_nums) {
const rank = [6,6,5,4,3,2,1];
const zeroCnt = lottos.filter(n=> !n).length;
const lottoSet = new Set([...lottos]);
const worst = new Set(win_nums.filter(n => lottoSet.has(n))).size;
return [rank[worst+zeroCnt], rank[worst]]
}