Task: Return the factorial of the provided integer.
Pseudocode:
- Get the integer value (n) as a parameter
- If the the number is equal to 0
- return 1
- return the value of n multiplied by result of n - 1
- If the the number is equal to 0
Actual Code:
function factorialize(num) {
// base case - if num is equal to 0, stop the recursion
if (num === 0) {
return 1;
}
// recursive case - will run except when num is equal to 0
return num * factorialize(num - 1);
}
factorialize(3); // 6