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.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68b7687dded630607aceccab Challenge 45: Perfect Square 28 challenge-45

--description--

Given an integer, determine if it is a perfect square.

  • A number is a perfect square if you can multiply an integer by itself to achieve the number. For example, 9 is a perfect square because you can multiply 3 by itself to get it.

--hints--

isPerfectSquare(9) should return true.

assert.isTrue(isPerfectSquare(9));

isPerfectSquare(49) should return true.

assert.isTrue(isPerfectSquare(49));

isPerfectSquare(1) should return true.

assert.isTrue(isPerfectSquare(1));

isPerfectSquare(2) should return false.

assert.isFalse(isPerfectSquare(2));

isPerfectSquare(99) should return false.

assert.isFalse(isPerfectSquare(99));

isPerfectSquare(-9) should return false.

assert.isFalse(isPerfectSquare(-9));

isPerfectSquare(0) should return true.

assert.isTrue(isPerfectSquare(0));

isPerfectSquare(25281) should return true.

assert.isTrue(isPerfectSquare(25281));

--seed--

--seed-contents--

function isPerfectSquare(n) {

  return n;
}

--solutions--

function isPerfectSquare(n) {
  if (n < 0) return false;
  const root = Math.floor(Math.sqrt(n));
  return root * root === n;
}