< 99 Elm Problems

Problem 2: Implement the function penultimate to find the next to last element of a list.

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"

Result:

3

Solutions

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.