Created
March 6, 2012 04:23
-
-
Save diegopacheco/1983448 to your computer and use it in GitHub Desktop.
Scala Recursion Tail Recursive
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(accumulator: Int, number: Int) : Int = { | |
| if(number == 1) return accumulator | |
| factorial(number * accumulator, number - 1) // Last thing you do you call a function.. will be tail recursive! | |
| } | |
| println(factorial(1,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment