Pack the same elements into a list inside a list.

antonrich

Anton

Posted on May 15, 2019

Pack the same elements into a list inside a list.

Again a challenge from 99 Elm problems

Convert a list to a list of lists where repeated elements of the source list are packed into sublists. Elements that are not repeated should be placed in a one element sublist.

pack [1,1,1,2,3,3,3,4,4,4,4,5,6,6] ==
    [ [1,1,1]
    , [2]
    , [3, 3, 3]
    , [4, 4, 4, 4]
    , [5]
    , [6, 6]
    ]
💖 💪 🙅 🚩
antonrich
Anton

Posted on May 15, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related