Created
April 14, 2025 14:24
-
-
Save paulohfev/c95a1cfb11b5b46aa9a9f5552da048b3 to your computer and use it in GitHub Desktop.
Calculate factorial with recursion
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
| // Calculate factorial via recursion | |
| const calculateFactorial = (num) => { | |
| if (num === 1) { | |
| return 1 | |
| } else { | |
| return num * calculateFactorial(num - 1) | |
| } | |
| } | |
| // console.log('3', calculateFactorial(3)) | |
| // console.log('5', calculateFactorial(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment