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.
1 parent 87e16d5 commit b400290Copy full SHA for b400290
1 file changed
Maths/WhileLoopFactorial.js
@@ -0,0 +1,20 @@
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)
9
+ return 1;
10
+ // Step 2. WHILE loop
11
+ while (num > 1) {
12
+ num--; // decrement 1 at each iteration
13
+ result = result * num; // or result = result * num;
14
+ }
15
+ // Step 3. Return the factorial
16
+ return result;
17
+}
18
+//test
19
+console.log(factorialize(5));
20
+console.log(factorialize(4));
0 commit comments