Last active
January 2, 2016 18:59
-
-
Save bobpace/8347254 to your computer and use it in GitHub Desktop.
fizzBuzzer in scala
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
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