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
68ffb91507a5b645769328c6 Challenge 103: LCM 28 challenge-103

--description--

Given two integers, return the least common multiple (LCM) of the two numbers.

The LCM of two numbers is the smallest positive integer that is a multiple of both numbers. For example, given 4 and 6, return 12 because:

  • Multiples of 4 are 4, 8, 12 and so on.
  • Multiples of 6 are 6, 12, 18 and so on.
  • 12 is the smallest number that is a multiple of both.

--hints--

lcm(4, 6) should return 12.

assert.equal(lcm(4, 6), 12);

lcm(9, 6) should return 18.

assert.equal(lcm(9, 6), 18);

lcm(10, 100) should return 100.

assert.equal(lcm(10, 100), 100);

lcm(13, 17) should return 221.

assert.equal(lcm(13, 17), 221);

lcm(45, 70) should return 630.

assert.equal(lcm(45, 70), 630);

--seed--

--seed-contents--

function lcm(a, b) {

  return a;
}

--solutions--

function lcm(a, b) {
  function gcd(x, y) {
    return y === 0 ? x : gcd(y, x % y);
  }

  return Math.abs(a * b) / gcd(a, b);
}