Problem 15 Solutions
Solution 1 - recurse
repeatElements : Int -> List a -> List a
repeatElements n list =
case list of
[] -> []
x :: xs ->
(List.repeat n x) ++ repeatElements n xs
Solution 2 - concatMap
repeatElements : Int -> List a -> List a
repeatElements n list =
List.concatMap (\x -> List.repeat n x) list
Solution 3 - fold
repeatElements : Int -> List a -> List a
repeatElements n list =
List.foldl (\x y -> y ++ (List.repeat n x)) [] list