99 Elm Problems/Problem 2/Solutions
< 99 Elm Problems | Problem 2
(Redirected from 99 Elm Problems/Lists/Problem 2: Find the next to last element of a list)Solution 1: Recursive search for the next to last element
penultimate list =
case list of
[] -> Nothing
next :: [_] -> Just next
_ :: tail -> penultimate tail
Solution 2: Functional composition
import List exposing (reverse, drop, head)
penultimate =
(reverse >> drop 1 >> head)