Skip to content

Instantly share code, notes, and snippets.

@jutikorn
Created July 22, 2017 07:13
Show Gist options
  • Save jutikorn/99a2038eff9e33e46888166f50c58fc8 to your computer and use it in GitHub Desktop.
Save jutikorn/99a2038eff9e33e46888166f50c58fc8 to your computer and use it in GitHub Desktop.
toc but no tailrec
private fun factorial(num: Double): Double {
return factorial(num, 1.0)
}
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