MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / GetEuclidGCD

Function GetEuclidGCD

Maths/GetEuclidGCD.js:13–23  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

11 * @returns {Number} Greatest Common Divisor gcd(a, b)
12 */
13export function GetEuclidGCD(a, b) {
14 CheckInput(a, b)
15 a = Math.abs(a)
16 b = Math.abs(b)
17 while (b !== 0) {
18 const rem = a % b
19 a = b
20 b = rem
21 }
22 return a
23}
24
25/**
26 * Recursive version of GetEuclidGCD

Callers 1

CoPrimeCheckFunction · 0.90

Calls 1

CheckInputFunction · 0.85

Tested by

no test coverage detected