跳到內容

99 Elm 問題/問題 2

來自維客圖書,開放世界的開放書籍

問題 2:實現函式 penultimate 以找出列表的倒數第二項。

import Html exposing (text)
import List
import Maybe

penultimate : List a -> Maybe a
-- your implementation goes here
  
main =
  case penultimate (List.range 1 4) of
    Just a -> text (toString a)
    Nothing -> text "No element found"

結果

3

解決方案

華夏公益教科書