Problem 08

This commit is contained in:
2026-03-19 15:39:20 +01:00
parent 78f56c809e
commit 659d211d8c
2 changed files with 32 additions and 0 deletions
@@ -0,0 +1,17 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem08:
def eliminateConsecutiveDuplicates(list: List[Any]): List[Any] =
@tailrec
def loop(cursor: List[Any], acc: List[Any]): List[Any] =
cursor match
case e1 :: e2 :: tail if e1 == e2 =>
loop(tail, e1 :: acc)
case e :: tail =>
loop(tail, e :: acc)
case Nil =>
acc
loop(list, List()).reverse