diff --git a/Algorithms.ts b/Algorithms.ts index 39e88d2..97838d5 100644 --- a/Algorithms.ts +++ b/Algorithms.ts @@ -619,3 +619,26 @@ export function findNumOccurrence(str: string, ch: string){ //Return the number of times the character appeared in the string return num; } +//This function returns the GCD of the two numbers sent to it +export function gcd(num1: number, num2: number){ + while((num1 != 0) && (num2 != 0)){ + if(num1 > num2){ + num1 %= num2; + } + else{ + num2 %= num1; + } + } + return num1 | num2; +} +export function gcdBig(num1: bigint, num2: bigint){ + while((num1 != 0n) && (num2 != 0n)){ + if(num1 > num2){ + num1 %= num2; + } + else{ + num2 %= num1; + } + } + return num1 | num2; +}