Created
March 5, 2023 00:11
-
-
Save fvilarino/fcfc41ae75015a5921995dea57de8dc4 to your computer and use it in GitHub Desktop.
Ticker - Alphabet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private object AlphabetMapper { | |
// 1 | |
private val Alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789•".toList() | |
val size: Int = Alphabet.size | |
// 2 | |
fun getLetterAt(index: Int): Char = Alphabet[index % size] | |
// 3 | |
fun getIndexOf(letter: Char): Int { | |
val index = Alphabet.indexOf(letter.uppercaseChar()) | |
return if (index < 0) Alphabet.lastIndex else index | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment