Skip to content

Instantly share code, notes, and snippets.

@krishnabhargav
Created July 25, 2014 00:33
Show Gist options
  • Save krishnabhargav/74e9f8bbb2f707fd8c78 to your computer and use it in GitHub Desktop.
Save krishnabhargav/74e9f8bbb2f707fd8c78 to your computer and use it in GitHub Desktop.
Factorial implemented using tail recursion
def factorial(number: Int) : Int = {
@tailrec def internalFactorial(seed: Int, num : Int) : Int = if (num > 1) internalFactorial (seed * num, num - 1) else num
internalFactorial(1, number)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment