Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68f6587287ad1f4ad39b0c83 Challenge 97: GCD 28 challenge-97

--description--

Given two positive integers, return their greatest common divisor (GCD).

  • The GCD of two integers is the largest number that divides evenly into both numbers without leaving a remainder.

For example, the divisors of 4 are 1, 2, and 4. The divisors of 6 are 1, 2, 3, and 6. So given 4 and 6, return 2, the largest number that appears in both sets of divisors.

--hints--

gcd(4, 6) should return 2.

assert.equal(gcd(4, 6), 2);

gcd(20, 15) should return 5.

assert.equal(gcd(20, 15), 5);

gcd(13, 17) should return 1.

assert.equal(gcd(13, 17), 1);

gcd(654, 456) should return 6.

assert.equal(gcd(654, 456), 6);

gcd(3456, 4320) should return 864.

assert.equal(gcd(3456, 4320), 864);

--seed--

--seed-contents--

function gcd(x, y) {

  return x;
}

--solutions--

function gcd(x, y) {
  while (y !== 0) {
    const temp = y;
    y = x % y;
    x = temp;
  }
  return x;
}