Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FizzBuzz implementation
class FizzBuzz(divisors = Map(3->"Fizz", 5->"Buzz")) {
def fizzBuzz(n: Int): String = {
divisors.foldLeft(""){(res, d)=>
n % d._1 match {
case 0 => res + d._2
case _ => res
}
} match {
case "" => n.toString
case str => str
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment