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