轉到內容

99 個 Elm 問題/問題 15

取自 Wikibooks,面向開放世界的開放書籍

重複給定列表的每個元素指定次數。

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]

結果

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

解決方案

華夏公益教科書