File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ All of these examples are from FreeCodeCamp's [course](https://www.freecodecamp.
13
13
- [ Basic Algorithm Scripting] ( #basic-algorithm-scripting )
14
14
- [ 1. Convert Celsius to Fahrenheit] ( #1-convert-celsius-to-fahrenheit )
15
15
- [ 2. Reverse a String] ( #2-reverse-a-string )
16
+ - [ 3. Factorialize a Number] ( #3-factorialize-a-number )
16
17
17
18
## Basic Algorithm Scripting
18
19
@@ -72,4 +73,49 @@ function reverseString(str) {
72
73
73
74
reverseString("hello");
74
75
76
+ ```
77
+
78
+ ### 3. Factorialize a Number
79
+
80
+ ### Difficulty: Beginner
81
+
82
+ Return the factorial of the provided integer.
83
+
84
+ If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
85
+
86
+ Factorials are often represented with the shorthand notation n!
87
+
88
+ For example: 5! = 1 _ 2 _ 3 _ 4 _ 5 = 120
89
+
90
+ Only integers greater than or equal to zero will be supplied to the function.
91
+
92
+ ---
93
+
94
+ ### Solution 1
95
+
96
+ ```
97
+ function factorialize(num) {
98
+ if (num === 0) {
99
+ return 1;
100
+ } else return num * factorialize(num - 1);
101
+ }
102
+
103
+ factorialize(5);
104
+
105
+ ```
106
+
107
+ ### Solution 2
108
+
109
+ ```
110
+ function factorialize(num) {
111
+ let factorializedNumber = 1;
112
+ for (let i = 2; i <= num; i++) {
113
+ factorializedNumber *= i;
114
+ }
115
+ return factorializedNumber;
116
+ }
117
+
118
+ factorialize(5);
119
+
120
+
75
121
```
You can’t perform that action at this time.
0 commit comments