99 道 Elm 习题/第 14 题/解答
外观
< 99 道 Elm 习题 | 第 14 题
解答 1:递归版本
duplicate list =
case list of
[] -> []
x :: xs -> x :: x :: duplicate xs
解答 2:使用 List.foldr
进行的无关键点版本
duplicate = List.foldr (\x xs -> x :: x :: xs) []
解答 1:递归版本
duplicate list =
case list of
[] -> []
x :: xs -> x :: x :: duplicate xs
解答 2:使用 List.foldr
进行的无关键点版本
duplicate = List.foldr (\x xs -> x :: x :: xs) []