Created
March 7, 2017 23:55
-
-
Save codemilli/7c37c1008020cfbc9a42cd6c04444469 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(number: Int) : Int = { | |
def factorialWithAccumulator(accumulator: Int, number: Int) : Int = { | |
if (number == 1) | |
return accumulator | |
else | |
factorialWithAccumulator(accumulator * number, number - 1) | |
} | |
factorialWithAccumulator(1, number) | |
} | |
println(factorial(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment