Skip to content

Instantly share code, notes, and snippets.

@LukaJCB
Created July 30, 2016 09:18
Show Gist options
  • Save LukaJCB/fbbc28f52b44e20753d947affa50dff7 to your computer and use it in GitHub Desktop.
Save LukaJCB/fbbc28f52b44e20753d947affa50dff7 to your computer and use it in GitHub Desktop.
def factorial(n: Int) : Int = {
@tailrec
def factorialWithAccumulator(acc: Int, n: Int) : Int = {
if (number == 1) acc
else factorialWithAccumulator(accumulator * n, n - 1)
}
factorialWithAccumulator(1, n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment