Programming, Scala, Data Type, Abstraction, Introduction.
gcd(a: Int, b: Int) : Int = if (b == 0) a else gcd(b, a % b) val numerator :Int = x / gcd(x, y) val denominator :Int = y / gcd(x, y) // ... } Finally declaring the numerator and denominator as val will ensure they are only computed once. The end result here is that no matter the implementation you