Problem 05

This commit is contained in:
2026-03-19 15:39:15 +01:00
parent 6864ee48c7
commit 79f245aaf4
2 changed files with 32 additions and 0 deletions
@@ -0,0 +1,19 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem05:
def reverseList(list: List[Any]): List[Any] =
@tailrec
def loop(cursor: List[Any], acc: List[Any]): List[Any] =
cursor match
case head :: tail =>
loop(tail, head :: acc)
case Nil =>
acc
loop(list, List())
object Problem05Stdlib:
def reverseList(list: List[Any]): List[Any] =
list.reverse