Skip to content

Instantly share code, notes, and snippets.

@bobpace
Last active January 2, 2016 18:59
Show Gist options
  • Save bobpace/8347254 to your computer and use it in GitHub Desktop.
Save bobpace/8347254 to your computer and use it in GitHub Desktop.
fizzBuzzer in scala
def fizzBuzzer(entries: Map[Int, String])(nums: Seq[Int]) = {
def fizzBuzzify(n: Int) =
(n, entries collect { case (key, value) if n % key == 0 => value })
nums map fizzBuzzify collect {
case (num, words) if !words.isEmpty => num + ": " + words.mkString(" ")
}
}
val answer = fizzBuzzer(Map(3 -> "fizz", 5 -> "buzz"))(0 to 100)
println(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment