Scala Solution with pattern matching


#1

This turns turns every element in the range into a tuple of true/false using modulo 3 ==0 and 5==0 then pattern matches on the tuple to determine if it’s a fizz, buzz,fizzbuzz or (default) value.

def fizzBuzz(A: Int): Array[String]  = {
  val v = for (i <- 1 to A) yield {
    (i % 3 == 0, i % 5 == 0) match {
      case (true, false) => "Fizz"
      case (false, true) => "Buzz"
      case (true, true) => "FizzBuzz"
      case _ => s"$i"
    }
  }
  v.toArray[String]
}