Skip to content

Instantly share code, notes, and snippets.

@edwingustafson
Last active April 6, 2020 15:19
Show Gist options
  • Save edwingustafson/b06131e7e172a86b2c3371b5e88d7a56 to your computer and use it in GitHub Desktop.
Save edwingustafson/b06131e7e172a86b2c3371b5e88d7a56 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala with no duplicated Strings or tests
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