Created
February 23, 2014 16:27
-
-
Save kretes/9173591 to your computer and use it in GitHub Desktop.
my first scala fizzbuzz solution
This file contains 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
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