Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69b559d2903b9e4afe9075f8.md
T
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.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69b559d2903b9e4afe9075f8 Challenge 238: Digit Rotation Escape 28 challenge-238

--description--

Given a positive integer, determine if it, or any of its rotations, is evenly divisible by its digit count.

A rotation means to move the first digit to the end. For example, after 1 rotation, 123 becomes 231.

  • Check rotation 0 (the given number) first.
  • Given numbers won't contain any zeros.
  • Return the first rotation number if one is found, or "none" if not.

--hints--

getRotation(123) should return 0.

assert.equal(getRotation(123), 0);

getRotation(13579) should return 3.

assert.equal(getRotation(13579), 3);

getRotation(24681) should return "none".

assert.equal(getRotation(24681), "none");

getRotation(84138789345) should return 6.

assert.equal(getRotation(84138789345), 6);

--seed--

--seed-contents--

function getRotation(n) {

  return n;
}

--solutions--

function getRotation(n) {
  const str = String(n);
  const digitCount = str.length;
  let current = str;

  for (let i = 0; i < digitCount; i++) {
    if (Number(current) % digitCount === 0) return i;
    current = current.slice(1) + current[0];
  }

  return "none";
}