Skip to content

Instantly share code, notes, and snippets.

@0xMarK
Created November 29, 2020 18:39
Show Gist options
  • Save 0xMarK/710a081e1056186669fc838b9fae3e62 to your computer and use it in GitHub Desktop.
Save 0xMarK/710a081e1056186669fc838b9fae3e62 to your computer and use it in GitHub Desktop.
Factorial
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