Last active
April 6, 2020 15:19
-
-
Save edwingustafson/b06131e7e172a86b2c3371b5e88d7a56 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala with no duplicated Strings or tests
This file contains hidden or 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 fizz = "Fizz" | |
val buzz = "Buzz" | |
val fizzBuzz = s"${fizz}${buzz}" | |
1 to 100 map { n => | |
(n % 3, n % 5) match { | |
case (0, 0) => fizzBuzz | |
case (0, _) => fizz | |
case (_, 0) => buzz | |
case _ => n | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment