🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of SergiiVlasiuk

SergiiVlasiuk's solution

to Acronym in the Scala Track

Published at Aug 23 2019 · 0 comments
Test suite

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

The Scala exercises assume an SBT project scheme. The exercise solution source should be placed within the exercise directory/src/main/scala. The exercise unit tests can be found within the exercise directory/src/test/scala.

To run the tests simply run the command sbt test in the exercise directory.

For more detailed info about the Scala track see the help page.


Julien Vanier https://github.com/monkbroc

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import org.scalatest.{Matchers, FunSuite}

/** @version 1.6.0 */
class AcronymTest extends FunSuite with Matchers {

  test("basic") {
    Acronym.abbreviate("Portable Network Graphics") should be ("PNG")

  test("lowercase words") {
    Acronym.abbreviate("Ruby on Rails") should be ("ROR")

  test("punctuation") {
    Acronym.abbreviate("First In, First Out") should be ("FIFO")

  test("all caps word") {
    Acronym.abbreviate("GNU Image Manipulation Program") should be ("GIMP")

  test("punctuation without whitespace") {
    Acronym.abbreviate("Complementary metal-oxide semiconductor") should be ("CMOS")

  test("very long abbreviation") {
    Acronym.abbreviate("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") should be ("ROTFLSHTMDCOALM")

  test("consecutive delimiters") {
    Acronym.abbreviate("Something - I made up from thin air") should be ("SIMUFTA")

  test("apostrophes") {
    Acronym.abbreviate("Halley's Comet") should be ("HC")
object Acronym {
  def abbreviate(phrase: String): String = """[^A-Za-z']""".r.split(phrase).filterNot(_.isEmpty)
    .map(_.charAt(0) toUpper) mkString

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?