Skip to content

Instantly share code, notes, and snippets.

@hooman
Last active August 29, 2015 14:11
Show Gist options
  • Save hooman/f9af191bfc9308e63ab4 to your computer and use it in GitHub Desktop.
Save hooman/f9af191bfc9308e63ab4 to your computer and use it in GitHub Desktop.
Another one of my Swift samples for RosettaCode.org
// Recursive:
func factorial(num: Int) -> Int {
return num < 2 ? 1 : num * factorial(num - 1)
}
// Iterative:
func factorial2(num: Int) -> Int {
return num < 2 ? 1 : reduce(1...num, 1, *)
}
factorial2(5)
factorial2(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment