Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d00790e

Browse files
solve: 1로 만들기
1 parent a67b445 commit d00790e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

‎Level0/PRO181880.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Solution 1
2+
const operationToMakeHalf = (num) => {
3+
return num % 2 === 0 ? num / 2 : (num - 1) / 2;
4+
};
5+
6+
const getCountOfOperationsToMakeOne = (num) => {
7+
let count = 0;
8+
9+
while (num > 1) {
10+
num = operationToMakeHalf(num);
11+
count += 1;
12+
}
13+
14+
return count;
15+
};
16+
17+
function solution(numList) {
18+
return numList.reduce((acc, cur) => acc + getCountOfOperationsToMakeOne(cur), 0);
19+
}

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,4 @@
288288
| 23.11.18. | `Level 0` | [l로 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/181834) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO181834.js) |
289289
| 23.11.18. | `Level 0` | [최빈값 구하기](https://school.programmers.co.kr/learn/courses/30/lessons/120812) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120812.js) |
290290
| 23.11.19. | `Level 0` | [합성수 찾기](https://school.programmers.co.kr/learn/courses/30/lessons/120846) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120846.js) |
291+
| 23.11.21. | `Level 0` | [1로 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/181880) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO181880.js) |

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /