문제
풀이 1
function solution(lottos, win_nums) {
var answer = [];
let count = 0
let zero = 0
let min
let max
const rank = {
'6' : 1,
'5' : 2,
'4' : 3,
'3' : 4,
'2' : 5,
'1' : 6,
'0' : 6,
}
lottos.map(v => {
if (v===0) zero++
if (win_nums.indexOf(v) !== -1) return count++
})
min = rank[count]
count = 0
let rest = []
win_nums.map(v => {
if (lottos.indexOf(v) !== -1) return count++
else rest.push(v)
})
rest.length >= zero ? count += zero : count += rest.length
max = rank[count]
return [max, min];
}
풀이 2
function solution(lottos, win_nums) {
let rank = [6,6,5,4,3,2,1]
let min = win_nums.filter(v => lottos.indexOf(v) !== -1).length
let zero = lottos.filter(v => !v).length
let rest = win_nums.length - min >= zero ? zero : win_nums.length - min
let max = min + rest
return [rank[max], rank[min]]
}