Skip to content

Instantly share code, notes, and snippets.

@filosganga
Created November 7, 2012 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filosganga/4031450 to your computer and use it in GitHub Desktop.
Save filosganga/4031450 to your computer and use it in GitHub Desktop.
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