How to resolve the algorithm Comma quibbling step by step in the Scala programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Comma quibbling step by step in the Scala programming language
Table of Contents
Problem Statement
Comma quibbling is a task originally set by Eric Lippert in his blog.
Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
Test your function with the following series of inputs showing your output here on this page:
Note: Assume words are non-empty strings of uppercase characters for this task.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Comma quibbling step by step in the Scala programming language
Source code in the scala programming language
def quibble( s:List[String] ) = s match {
case m if m.isEmpty => "{}"
case m if m.length < 3 => m.mkString("{", " and ", "}")
case m => "{" + m.init.mkString(", ") + " and " + m.last + "}"
}
// A little test...
{
println( quibble( List() ) )
println( quibble( List("ABC") ) )
println( quibble( List("ABC","DEF") ) )
println( quibble( List("ABC","DEF","G","H") ) )
}
You may also check:How to resolve the algorithm Largest proper divisor of n step by step in the Fortran programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the Racket programming language
You may also check:How to resolve the algorithm Strassen's algorithm step by step in the Julia programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the D programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the Modula-2 programming language