Created
July 22, 2017 07:17
-
-
Save jutikorn/6e975f78efec018e9e85dc82a6253894 to your computer and use it in GitHub Desktop.
tailrec
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
private fun factorial(num: Double): Double { | |
return factorial(num, 1.0) | |
} | |
tailrec fun factorial(num: Double, result: Double): Double { | |
when (num) { | |
0.0 -> | |
return result | |
else -> | |
return factorial(num-1, num * result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment