Sha256: 219683521b1b15c66bb6ed36c6b5ba16e2fe62ebe71c8b2afc8c8a43caafc7bd

Contents?: true

Size: 519 Bytes

Versions: 139

Compression:

Stored size: 519 Bytes

Contents

object PigLatin {
  private val vowelRegex = "(^|\\s+)(a|e|i|o|u|yt|xr)(\\w+)".r
  private val consonantRegex = "(^|\\s+)(?<consonant>ch|qu|thr|th|sch|yt|rh|\\wqu|\\w)(?<rest>\\w+)".r
  private val vowelReplacement = "$1$2$3ay"
  private val consonantReplacement = "$1$3$2ay"

  def translate(phrase: String): String =
    vowelRegex.findFirstIn(phrase) match {
      case Some(x) => vowelRegex.replaceAllIn(phrase, vowelReplacement)
      case None => consonantRegex.replaceAllIn(phrase, consonantReplacement)
    }
}

Version data entries

139 entries across 139 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.179 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.178 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.177 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.176 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.175 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.174 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.173 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.172 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.171 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.170 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.169 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.167 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.166 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.165 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.164 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.163 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.162 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.161 tracks/scala/exercises/pig-latin/example.scala
trackler-2.2.1.160 tracks/scala/exercises/pig-latin/example.scala