Problem 04

This commit is contained in:
2026-03-19 15:39:13 +01:00
parent 6504948100
commit 6864ee48c7
2 changed files with 31 additions and 0 deletions
@@ -0,0 +1,19 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem04:
def listLength(list: List[Any]): Int =
@tailrec
def loop(cursor: List[Any], acc: Int): Int =
cursor match
case head :: tail =>
loop(tail, acc + 1)
case Nil =>
acc
loop(list, 0)
object Problem04Stdlib:
def listLength(list: List[Any]): Int =
list.length