Last active
June 19, 2020 05:17
-
-
Save texora/85b0d76cca4a2fbb1aafea95cfa9265c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function power(num, pow) { | |
return pow !== 0 ? num * power(num, pow - 1) : 1; | |
} | |
function factorial(num) { | |
return num !== 0 ? num * factorial(num - 1) : 1; | |
} | |
// test | |
factorial(5) | |
5 * factorial(4) | |
4 * factorial (3) | |
3 * factorial(2) | |
2 * factorial(1) | |
1 * factorial(0) | |
1 | |
1 | |
1 * 1 | |
2 * 1 * 1 | |
3 * 2 * 1 * 1 | |
4 * 3 * 2 * 1 * 1 | |
5 * 4 * 3 * 2 * 1 * 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment