I have created the following function, which takes two Integers
as parameters and computes the GCD of them:
func getGCD(_ num1: Int, _ num2: Int) -> Int {
let remainder = num1 % num2
if remainder != 0 {
return gcd(num2, remainder)
} else {
return num2
}
}
NOTE: I want to use Recursivity
.
Question 1: Is there any way to make this function more efficient?
Question 2: How can I use this function for an Array
of type [Int]
?