< 99 Elm Problems

Pack consecutive duplicates of list elements into sublists. If a list contains repeated elements they should be placed in separate sublists. Elements that are not repeated should be placed in a one element sublist.

import Html exposing (text)
import List

pack : List a -> List (List a)
-- your implementation goes here

main = pack [1,1,1,2,3,3,3,4,4,4,4,5,6,6] |> toString |> text

Result:

[[1,1,1], [2], [3, 3, 3], [4, 4, 4, 4], [5], [6, 6]]

Solutions

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.