Skip to content

Instantly share code, notes, and snippets.

@kretes
Created February 23, 2014 16:27
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 kretes/9173591 to your computer and use it in GitHub Desktop.
Save kretes/9173591 to your computer and use it in GitHub Desktop.
my first scala fizzbuzz solution
package katas
object FizzBuzz {
def fizzBuzz(input:Int):String = {
class Solution(val result:String, val filter:Int) {
def isSatisfied(input:Int) = {
input % filter == 0 || input.toString.contains(filter.toString)
}
}
val solutions = List(new Solution("fizz",3),new Solution("buzz",5))
val matchingSolutions: List[Solution] = solutions.filter(solution => solution.isSatisfied(input))
matchingSolutions match {
case Nil => input.toString
case list:List[Solution] => list.map(_.result).mkString("")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment