DEV Community

Discussion on: Daily Challenge #206 - Pound Means Backspace

Collapse
 
avalander profile image
Avalander

Scala

  def cleanString (str: String): String = {
    (str.toList.foldLeft(List[Char]()) {
      case (Nil, '#')     => Nil
      case (x :: xs, '#') => xs
      case (xs, c)        => c :: xs
    }).reverse.mkString
  }