Problem 04
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user