DEV Community

Discussion on: Daily Challenge #206 - Pound Means Backspace

Collapse
 
cipharius profile image
Valts Liepiņš

Haskell:

cleanString :: String -> String
cleanString = reverse . clean 0 . reverse
  where
    clean :: Int -> String -> String
    clean _ "" = ""
    clean d ('#':rest) = clean (d + 1) rest
    clean 0 (ch:rest)  = ch : clean 0 rest
    clean d (ch:rest)  = clean (d - 1) rest