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 1dd1780

Browse files
solve: 팩토리얼
1 parent 94bb8a7 commit 1dd1780

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎Level0/PRO120848.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Solution 1
2+
function solution1(n) {
3+
let num = 1;
4+
let sum = 1;
5+
6+
while (n >= sum) {
7+
num += 1;
8+
sum *= num;
9+
}
10+
11+
return num - 1;
12+
}
13+
14+
// Solution 2
15+
const MAX_N = 11;
16+
17+
function factorial(num) {
18+
if (num <= 1) {
19+
return 1;
20+
}
21+
22+
return num * factorial(num - 1);
23+
}
24+
25+
function solution2(n) {
26+
for (let i = 1; i <= MAX_N; i++) {
27+
if (factorial(i) > n) {
28+
return i - 1;
29+
}
30+
}
31+
}

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,4 @@
298298
| 23.11.27. | `Level 0` | [순서쌍의 개수](https://school.programmers.co.kr/learn/courses/30/lessons/120836) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120836.js) |
299299
| 23.11.28. | `Level 0` | [분수의 덧셈](https://school.programmers.co.kr/learn/courses/30/lessons/120808) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120808.js) |
300300
| 23.11.29. | `Level 0` | [2차원으로 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/120842) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120842.js) |
301+
| 23.11.30. | `Level 0` | [팩토리얼](https://school.programmers.co.kr/learn/courses/30/lessons/120848) | [JS](https://github.com/JeongHwan-dev/Algorithm-solving-with-js/blob/master/Level0/PRO120848.js) |

0 commit comments

Comments
(0)

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