LoginSignup
0
0

More than 5 years have passed since last update.

99 PSiE [Problem 2]

Posted at

はじめに

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

正解

=> Problem 2 Solutions

コメント

よくよくみたら、ユニットテスト(もどき)があるのですね。気が付きませんでした。次は気をつけます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0