[프로그래머스] 로또의 최고 순위와 최저 순위 (javascript)
728x90
반응형
이미 맞춘 번호들 개수를 세줌 (최저)
0인 부분을 모두 더해줌 (최대)
function solution(lottos, win_nums) {
var answer = [];
let cnt=lottos.length;
//없는 번호만
lottos=lottos.filter(lotto=>win_nums.indexOf(lotto)===-1);
cnt-=lottos.length;//맞춘 개수, 최저 맞춘 개수
let min=cnt;
let max=cnt+lottos.reduce((acc,cur)=>{
if(cur===0)acc+=1;
return acc;
},0);
// console.log(min,max)
function rank(x){
if(x===6)return 1;
else if(x===5)return 2;
else if(x===4)return 3;
else if(x===3)return 4;
else if (x===2)return 5;
else return 6;
}
return [rank(max),rank(min)];
}
728x90
반응형
'프로그래머스' 카테고리의 다른 글
[프로그래머스] 행렬 테두리 회전하기 (javascript) (0) | 2021.04.30 |
---|---|
[프로그래머스] n 개의 최소공배수 (javascript) (0) | 2021.04.30 |
[프로그래머스] 배달 (javascript) (0) | 2021.04.28 |
[프로그래머스] 점프와 순간 이동 (Javascript) (0) | 2021.04.28 |
[프로그래머스] 방문 길이 (javascript) (0) | 2021.04.24 |
TAGS.