findAllIn

Ακρώνυμο
Ακρώνυμο στη διαδρομή Scala
object Acronym {
  def abbreviate(phrase: String): String = {
    raw"[\p{L}']+".r
      .findAllIn(phrase)
      .map(_.head.toUpper)
      .mkString
  }
}

This approach starts by defining a Regex pattern using a raw interpolator. The raw interpolator allows using the backslash escape character in a Regex patttern without having to escape the backslash with another backslash. The pattern looks for one or more Unicode letter or dash characters.

The Regex calls its findAllIn() method, which finds all non-overlapping matches of the Regex pattern in the input phrase. The resulting MatchIterator of words is chained to the map() method, which calls toUpper() on the head of each word and passes the uppercased first character of each word to the mkString() method, which returns all of those characters from the abbreviate() method as a String.

Translation missing: el.number.nth.ordinalized Sep 2026 · Σου φάνηκε χρήσιμη;

Άλλες προσεγγίσεις για την άσκηση Ακρώνυμο στη διαδρομή Scala

Άλλοι τρόποι με τους οποίους η κοινότητά μας έλυσε αυτή την άσκηση