How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Scala programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Scala programming language
Table of Contents
Problem Statement
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence. For this basic task use a reliable style of coding, a style fit for a very large program, and use strong typing if available. It's bug prone to enumerate all the lowercase characters manually in the code. During code review it's not immediate obvious to spot the bug in a Tcl line like this contained in a page of code:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Scala programming language
Source code in the scala programming language
object Abc extends App {
val lowAlpha = 'a' to 'z' //That's all
// Now several tests
assert(lowAlpha.toSeq == Seq('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'),
"No complete lowercase alphabet.")
assert(lowAlpha.size == 26, "No 26 characters in alphabet")
assert(lowAlpha.start == 'a', "Character 'a' not first char! ???")
assert(lowAlpha.head == 'a', "Character 'a' not heading! ???")
assert(lowAlpha.head == lowAlpha(0), "Heading char is not first char.")
assert(lowAlpha contains 'n', "Character n not present.")
assert(lowAlpha.indexOf('n') == 13, "Character n not on the 14th position.")
assert(lowAlpha.last == lowAlpha(25), "Expected character (z)on the last and 26th pos.")
println(s"Successfully completed without errors. [within ${
scala.compat.Platform.currentTime - executionStart
} ms]")
}
You may also check:How to resolve the algorithm Pentomino tiling step by step in the Nim programming language
You may also check:How to resolve the algorithm Sort an outline at every level step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Scope/Function names and labels step by step in the Python programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the Elixir programming language
You may also check:How to resolve the algorithm Stack step by step in the Logtalk programming language