[Home] >  Number >  Compute the greatest common divisor between two numbers

Compute the greatest common divisor between two numbers

JavaScript version

const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));

TypeScript version

const gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));

Examples

gcd(10, 15); // 5