Skip to content

Instantly share code, notes, and snippets.

@jhigdon
Last active August 29, 2015 14:01
Show Gist options
  • Save jhigdon/a0c091ad91fe432471b6 to your computer and use it in GitHub Desktop.
Save jhigdon/a0c091ad91fe432471b6 to your computer and use it in GitHub Desktop.
@JSExport
object ScalaJSExample {
def fizzBuzz(a: List[Int], divisor1: Int, divisor2: Int): List[Any] = {
a.map {
x =>
((x % divisor1 == 0, x % divisor2 == 0) match {
case (true, false) => "fizz"
case (false, true) => "buzz"
case (true, true) => "fizzbuzz"
case (false, false) => x
})
}
}
@JSExport
def main(args: Array[String]): Unit = {
fizzBuzz(List.range(1, 101), 3, 5).foreach(x => println(x))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment