Created
July 30, 2016 09:18
-
-
Save LukaJCB/fbbc28f52b44e20753d947affa50dff7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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