Project Nayuki

Calculate GCD (JavaScript)



This JavaScript program calculates the greatest common divisor (GCD) of the given integers. The numbers must be between 0 and 253. This program can be useful for simplifying fractions. The algorithm being used is the classic GCD algorithm by Euclid, which is very fast.

The source code is available for viewing.


  • gcd(0, 2) = 2.
  • gcd(3, 5) = 1.
  • gcd(24, 18) = 6.

More info