Ad

Leading characters that are not letters should be ignored.

Added relevant test cases.

Code
Diff
  • module ToUpperFirst where
    
    import Data.Char (toUpper, isLetter)
    
    toUpperFirst :: String -> String
    toUpperFirst str =
      case break isLetter str of
        (xs, y:ys) -> xs ++ toUpper y : ys
        _          -> str
    • module ToUpperFirst where
    • import Data.Char (toUpper, isSpace)
    • toUpperFirst (x : xs) = if isSpace x then x : toUpperFirst xs else toUpper x : xs
    • toUpperFirst _ = ""
    • import Data.Char (toUpper, isLetter)
    • toUpperFirst :: String -> String
    • toUpperFirst str =
    • case break isLetter str of
    • (xs, y:ys) -> xs ++ toUpper y : ys
    • _ -> str

Added tests for negative integers, modified solution so it doesn't rely on Show instance of Int.

Code
Diff
  • module AreThereThree where
    
    solution :: Int -> Bool
    solution = go . abs
      where
        go 0 = False
        go x = let (x', y) = x `divMod` 10 in y == 3 || go x'
    
    • module AreThereThree where
    • solution :: Int -> Bool
    • solution = elem '3' . show
    • solution = go . abs
    • where
    • go 0 = False
    • go x = let (x', y) = x `divMod` 10 in y == 3 || go x'