DEV Community

Discussion on: Daily Challenge #179 - Hide Phone Numbers

Collapse
 
zoejm profile image
zoe-j-m

Scala,

def encryptNum(input : String) = {
  def encryptInner(remain : Int, toGo : List[Char]) : List[Char] = {
    toGo match {
      case Nil => Nil
      case _ if remain == 0 => toGo
      case x::xs if x.isDigit => 'X' :: encryptInner(remain - 1, xs)
      case x::xs => x :: encryptInner(remain, xs)
    }
  }

  encryptInner(6, input.reverse.toList).reverse.mkString
}