mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-16 07:00:53 -04:00
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com> Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
1.6 KiB
1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6821ebc9237de8297eaee78f | JavaScript Challenge 13: Unnatural Prime | 28 | javascript-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.
1and0are 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;
}