Created
November 29, 2020 18:39
-
-
Save 0xMarK/710a081e1056186669fc838b9fae3e62 to your computer and use it in GitHub Desktop.
Factorial
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
func factorialRecursive(_ number: Int) -> Int { | |
if number < 3 { | |
return number | |
} | |
return number * factorialRecursive(number - 1) | |
} | |
func factorialIterative(_ number: Int) -> Int { | |
var result = 1 | |
for i in (2...number) { | |
result *= i | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment