跳轉到內容

99 道 Elm 難題/問題 3

來自華夏公益教科書——面向開放世界的開放書籍

問題 3:實現函式 nth,以返回列表的第 n 個元素。

import Html exposing (text)
import List exposing (head, length)
import Maybe

nth: Int -> List a -> Maybe a
-- your implementation goes here

main =
  case (nth 2 (List.range 1 4)) of
    Just a -> text (toString a)
    Nothing -> text "No element found"

結果

3

解答

華夏公益教科書