August 27, 2024

P08 - Eliminate consecutive duplicates of list elements.

If a list contains repeated elements they should be replaced with a single copy of the element.  The order of the elements should not be changed.

Example:

scala

scala> compress(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))
res0: List[Symbol] = List('a, 'b, 'c, 'a, 'd, 'e)
Be first to comment
Leave a reply