Last active
August 21, 2024 09:31
-
-
Save alishahlakhani/1cf7ab74a1c7f66f434eafeae289b29a to your computer and use it in GitHub Desktop.
Algorithm // Finding Greatest Common Divisor in Typescript using Euclidean algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findGDC(num1: number, num2: number): number { | |
function calcMod(v1: number, v2: number): number { | |
return v1 % v2; | |
} | |
let a = num1; | |
let b = num2; | |
while (b > 0) { | |
const mod = calcMod(a, b); | |
if (mod === 0) break; | |
a = b; | |
b = mod; | |
} | |
return b; | |
} | |
console.log("Greatest Common Divisor =", findGDC(692, 908)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment