Created
May 9, 2020 15:55
-
-
Save iamamit-107/7ceb1053250d5f4974d7e4986d52652b to your computer and use it in GitHub Desktop.
This file contains 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 iterativeFactorial(num) { | |
if (num === 0 || num === 1) { | |
return 1; | |
} | |
for (let i = num - 1; i >= 1; i--) { | |
num = num * i; | |
} | |
return num; | |
} | |
console.log(iterativeFactorial(5)); | |
//output: 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment