Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created May 18, 2014 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/f8c59900cfb29e24967b to your computer and use it in GitHub Desktop.
Save adilakhter/f8c59900cfb29e24967b to your computer and use it in GitHub Desktop.
factorial-tail-rec
def factorial(n: Int): Int = {
@tailrec def factorialAcc(acc: Int, n:Int): Int = {
if (n<=1) acc else factorialAcc(acc*n, n-1)
}
factorialAcc(1,n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment