Skip to content

Instantly share code, notes, and snippets.

@alishahlakhani
Created August 21, 2024 09:58
Show Gist options
  • Select an option

  • Save alishahlakhani/64827d7964f34c2641a2b2cd47a02707 to your computer and use it in GitHub Desktop.

Select an option

Save alishahlakhani/64827d7964f34c2641a2b2cd47a02707 to your computer and use it in GitHub Desktop.
Algorithm // Finding LCM in Typescript using Euclidean algorithm
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;
}
function findLCM(num1: number, num2: number): number {
const gcd = findGDC(num1, num2);
return (num1 * num2) / gcd;
}
const num1 = 692;
const num2 = 908;
console.log("LCM =", findLCM(num1, num2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment