반응형
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
- Algorithm
- type challenge
- javascript
- 자바스크립트
- 쉬운 문제
- 프로그래머스
- Crawling
- 백준
- 문자열
- TCP
- 소켓
- 타입 챌린지
- 그래프
- Nestjs
- socket
- ip
- 타입스크립트
- 알고리즘
- 가천대
- 수학
- 프로그래머스 레벨 2
- BFS
- HTTP 완벽 가이드
- 크롤링
- Node.js
- HTTP
- 레벨 1
- typescript
- dfs
- dp
Archives
- Today
- Total
kakasoo
[node.js] k번째 수 ( 프로그래머스 레벨1 ) 본문
반응형
// 프로그래머스 level1 k번째 수
const solution = (array, commands) => new Array(commands.length).fill(0).map((el, i) => i + 1).map(el => array.slice(commands[el-1][0] - 1, commands[el-1][1]).sort((o1, o2) => o1 - o2)[commands[el-1][2] -1]);
이 때 내가 왜 이렇게 풀었는지 기억이 나지 않는다. 그냥 함수형 컨셉을 해보고 싶었던 모양이다.
당연히 저런 가독성 없는 코드를 평소에도 짜는 건 아니다.
const solution = (array, commands) => {
const answer = [];
commands.forEach((line) => {
const [start, end, index] = line;
answer.push(array.slice(start - 1, end).sort((a,b) => a - b)[index - 1]);
})
return answer;
}
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 체육복 ( 프로그래머스 레벨1 ) (0) | 2021.06.25 |
---|---|
[node.js] 모의고사 ( 프로그래머스 레벨1 ) (0) | 2021.06.25 |
[node.js] 크레인 인형 뽑기 ( 프로그래머스 레벨1 ) (0) | 2021.06.25 |
[node.js] 날짜 계산 ( 백준 1476번 ) (0) | 2021.05.12 |
[node.js] 일곱 난쟁이 ( 백준 2309번 ) (0) | 2021.05.12 |