Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created October 7, 2018 14:51
Show Gist options
  • Save Nublo/7c8a0d2dd2aa56d788477742d98b5101 to your computer and use it in GitHub Desktop.
Save Nublo/7c8a0d2dd2aa56d788477742d98b5101 to your computer and use it in GitHub Desktop.
fun sum(xs: List<Int>):Int {
tailrec fun sumInner(xs: List<Int>, acum: Int): Int = when (xs.size) {
0 -> acum
else -> sumInner(xs.tail, xs.head + acum)
}
return sumInner(xs, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment