Created
March 16, 2020 18:59
-
-
Save Hoobie/f162a00aeb4dcbdf5195c2c3b81c6fc8 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 = if (n > 1) n * factorial(n - 1) else 1 | |
@scala.annotation.tailrec | |
def tailFactorial(n: Int, acc: Int = 1): Int = | |
if (n == 1) acc | |
else tailFactorial(n - 1, n * acc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment