DEV Community

loading...

Discussion on: Daily Challenge #190 - capitalizeFirstLast

Collapse
craigmc08 profile image
Craig McIlwrath

Haskell

import Data.Char (toUpper, toLower)

capitalizeFirstLast :: String -> String
capitalizeFirstLast = unwords . map f . words
  where f (c:[]) = [toUpper c]
        f (c:cs) = toUpper c : map toLower (init cs) ++ [toUpper (last cs)]