99 Elm Problems/Problem 15

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Repeat each element of a list a given number of times.

import Html exposing (text)
import List

repeatElements : Int -> List a -> List a
-- your implementation goes here

main = 
  text <| toString <|
    repeatElements 3 [1, 2, 3, 3]

Result:

[1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3]

Solutions