Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/6821ebc9237de8297eaee78f.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.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6821ebc9237de8297eaee78f Challenge 13: Unnatural Prime 28 challenge-13

--description--

Given an integer, determine if that number is a prime number or a negative prime number.

  • A prime number is a positive integer greater than 1 that is only divisible by 1 and itself.
  • A negative prime number is the negative version of a positive prime number.
  • 1 and 0 are not considered prime numbers.

--hints--

isUnnaturalPrime(1) should return false.

assert.isFalse(isUnnaturalPrime(1));

isUnnaturalPrime(-1) should return false.

assert.isFalse(isUnnaturalPrime(-1));

isUnnaturalPrime(19) should return true.

assert.isTrue(isUnnaturalPrime(19));

isUnnaturalPrime(-23) should return true.

assert.isTrue(isUnnaturalPrime(-23));

isUnnaturalPrime(0) should return false.

assert.isFalse(isUnnaturalPrime(0));

isUnnaturalPrime(97) should return true.

assert.isTrue(isUnnaturalPrime(97));

isUnnaturalPrime(-61) should return true.

assert.isTrue(isUnnaturalPrime(-61));

isUnnaturalPrime(99) should return false.

assert.isFalse(isUnnaturalPrime(99));

isUnnaturalPrime(-44) should return false.

assert.isFalse(isUnnaturalPrime(-44));

--seed--

--seed-contents--

function isUnnaturalPrime(n) {

  return n;
}

--solutions--

function isUnnaturalPrime(n) {
  const abs = Math.abs(n);

  if (abs <= 1) return false;

  for (let i = 2; i <= Math.sqrt(abs); i++) {
    if (abs % i === 0) return false;
  }

  return true;
}