はじめに
Ninety-nine Problems, Solved in Elm を毎日さわることで、Elm に親しもうという『日記』です。詳細は 99 PSiE [Problem 1] をご覧ください。
問題
Implement the function penultimate to find the next to last element of a list.
成果物
import Html
import Browser
main = Html.text
<| Debug.toString
<| penultimate_ [1,2,3,4]
-- Here is my solution.
penultimate : List a -> Maybe a
penultimate list =
let
reversedList = List.reverse list
in
case reversedList of
x::y::ys -> Just y
_ -> Nothing
正解
コメント
よくよくみたら、ユニットテスト(もどき)があるのですね。気が付きませんでした。次は気をつけます。