반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 자바스크립트
- javascript
- 수학
- 크롤링
- 문자열
- 백준
- 알고리즘
- BFS
- dfs
- Algorithm
- HTTP 완벽 가이드
- 프로그래머스 레벨 2
- socket
- 레벨 1
- 그래프
- 가천대
- 소켓
- Crawling
- 타입 챌린지
- HTTP
- 쉬운 문제
- typescript
- 타입스크립트
- type challenge
- Node.js
- ip
- TCP
- 프로그래머스
- Nestjs
- dp
Archives
- Today
- Total
kakasoo
[node.js] 로또의 최고 순위와 최저 순위 ( 프로그래머스 레벨1 ) 본문
반응형
// 프로그래머스 레벨1 로또의 최고 순위와 최저 순위를 풀었습니다.
const setRank = (n) => {
switch (n) {
case 6:
return 1;
case 5:
return 2;
case 4:
return 3;
case 3:
return 4;
case 2:
return 5;
case 1:
case 0:
return 6;
}
};
const solution = (lottos, win_nums) => {
const numbers = lottos.filter((el) => el !== 0);
const zeros = lottos.filter((el) => el === 0);
let count = 0;
numbers.forEach((num) => {
if (win_nums.includes(num)) {
count++;
}
});
return [setRank(count + zeros.length), setRank(count)];
};
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 수식 최대화 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 |
---|---|
[node.js] 신규 아이디 추천 ( 프로그래머스 레벨1 ) (0) | 2021.06.30 |
[node.js] 폰켓몬 ( 프로그래머스 레벨1 ) (0) | 2021.06.30 |
[node.js] 음양 더하기 ( 프로그래머스 레벨1 ) (0) | 2021.06.30 |
[node.js] 약수의 개수와 덧셈 ( 프로그래머스 레벨1 ) (0) | 2021.06.30 |