https://programmers.co.kr/learn/courses/30/lessons/77484
// me
// 최고 최저 순위와 일치하는 개수 구분!
function solution(lottos, win_nums) {
var answer = [];
// 최저 - 교집합
const common = lottos.filter(num => win_nums.includes(num));
const lowest = common.length;
const placeOfLowest = lowest >=2 ? 7-lowest : 6;
console.log(lowest);
// 최고 = 최저 + 0의 개수
const numOfZero = lottos.filter(num => num === 0).length;
const highest = numOfZero + lowest;
const placeOfHighest = highest >=2 ? 7-highest : 6;
console.log(highest);
// 예외처리
answer = [placeOfHighest, placeOfLowest];
return answer;
}
// other
// 바로 push, 예외처리 간단, 가독성
function solution(lottos, win_nums) {
const answer = [];
const min = lottos.filter(n => win_nums.includes(n)).length;
const max = lottos.filter(n => n === 0).length + min;
max > 1 ? answer.push(7 - max) : answer.push(6);
min > 1 ? answer.push(7 - min) : answer.push(6);
return answer;
}