Created
August 28, 2018 22:04
-
-
Save gustavofranke/f3dfd76f8eff64e8618aa793a483dea3 to your computer and use it in GitHub Desktop.
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
val toEnglish = Map((0, 4) -> "four", (1, 3) -> "thirty", (2, 2) -> "two hundreds", (3, 1) -> "one thousand") | |
def intToEnglish(a: Int): String = a.toString.toList | |
.map { _.toString.toInt } | |
.reverse.zipWithIndex.reverse | |
.map { t => toEnglish(t.swap) } | |
.mkString(" ") | |
intToEnglish(4) // res0: String = four | |
intToEnglish(34) // res1: String = thirty four | |
intToEnglish(234) // res2: String = two hundreds thirty four | |
intToEnglish(1234) // res3: String = one thousand two hundreds thirty four |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment