Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9c9640c + 4e680d7 commit 1929509Copy full SHA for 1929509
1 file changed
Maths/WhileLoopFactorial.js
@@ -0,0 +1,19 @@
1
+/*
2
+ author: Theepag
3
+ */
4
+const factorialize = (num) => {
5
+ // Step 1. variable result to store num
6
+ let result = num
7
+ // If num = 0 OR 1, the factorial will return 1
8
+ if (num === 0 || num === 1) { return 1 }
9
+ // Step 2. WHILE loop
10
+ while (num > 1) {
11
+ num-- // decrement 1 at each iteration
12
+ result = result * num // or result = result * num;
13
+ }
14
+ // Step 3. Return the factorial
15
+ return result
16
+}
17
+// test
18
+console.log(factorialize(5))
19
+console.log(factorialize(4))
0 commit comments