Skip to content

Instantly share code, notes, and snippets.

@jutikorn
Created July 22, 2017 07:17
Show Gist options
  • Save jutikorn/6e975f78efec018e9e85dc82a6253894 to your computer and use it in GitHub Desktop.
Save jutikorn/6e975f78efec018e9e85dc82a6253894 to your computer and use it in GitHub Desktop.
tailrec
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