As far as I can tell, you don't want a simple number but a prime number.
I added 5075 as it's also not a prime number.
export const checkIsPrimeNumber = (n: number) => { if (!Number.isInteger(n)) return false; for (var i = 2; i < n; i++) { if (n % i === 0) return false; } return n > 1; };
export const checkIsNumberSimple = (number: number) => {// Check if the number is integerif (number % 1 != 0) return false;if (number < 2) return false;if (number != 2 && number % 2 == 0) return false;if (number != 3 && number % 3 == 0) return false;return true;- export const checkIsPrimeNumber = (n: number) =>
- {
- if (!Number.isInteger(n)) return false;
- for (var i = 2; i < n; i++) {
- if (n % i === 0) return false;
- }
- return n > 1;
- };
// See https://www.chaijs.com for how to use Chai. import { assert } from "chai"; import { checkIsPrimeNumber } from "./solution"; describe("Prime numbers", function() { it("should not be negative numbers", function() { assert.strictEqual(checkIsPrimeNumber(-1), false); }); it("should be integer numbers", function() { assert.strictEqual(checkIsPrimeNumber(3.1), false); }); it("should be prime numbers", function() { assert.strictEqual(checkIsPrimeNumber(2), true); assert.strictEqual(checkIsPrimeNumber(3), true); assert.strictEqual(checkIsPrimeNumber(5), true); assert.strictEqual(checkIsPrimeNumber(3571), true); assert.strictEqual(checkIsPrimeNumber(5075), false); assert.strictEqual(checkIsPrimeNumber(5077), true); assert.strictEqual(checkIsPrimeNumber(0), false); assert.strictEqual(checkIsPrimeNumber(1), false); assert.strictEqual(checkIsPrimeNumber(4), false); assert.strictEqual(checkIsPrimeNumber(3572), false); }); });
- // See https://www.chaijs.com for how to use Chai.
- import { assert } from "chai";
import { checkIsNumberSimple } from "./solution";- import { checkIsPrimeNumber } from "./solution";
// TODO Add your tests heredescribe("Simple numbers", function() {- describe("Prime numbers", function() {
- it("should not be negative numbers", function() {
assert.strictEqual(checkIsNumberSimple(-1), false);- assert.strictEqual(checkIsPrimeNumber(-1), false);
- });
- it("should be integer numbers", function() {
assert.strictEqual(checkIsNumberSimple(3.1), false);- assert.strictEqual(checkIsPrimeNumber(3.1), false);
- });
it("should be simple numbers", function() {assert.strictEqual(checkIsNumberSimple(2), true);assert.strictEqual(checkIsNumberSimple(3), true);assert.strictEqual(checkIsNumberSimple(5), true);assert.strictEqual(checkIsNumberSimple(3571), true);assert.strictEqual(checkIsNumberSimple(0), false);assert.strictEqual(checkIsNumberSimple(1), false);assert.strictEqual(checkIsNumberSimple(4), false);assert.strictEqual(checkIsNumberSimple(3572), false);- it("should be prime numbers", function() {
- assert.strictEqual(checkIsPrimeNumber(2), true);
- assert.strictEqual(checkIsPrimeNumber(3), true);
- assert.strictEqual(checkIsPrimeNumber(5), true);
- assert.strictEqual(checkIsPrimeNumber(3571), true);
- assert.strictEqual(checkIsPrimeNumber(5075), false);
- assert.strictEqual(checkIsPrimeNumber(5077), true);
- assert.strictEqual(checkIsPrimeNumber(0), false);
- assert.strictEqual(checkIsPrimeNumber(1), false);
- assert.strictEqual(checkIsPrimeNumber(4), false);
- assert.strictEqual(checkIsPrimeNumber(3572), false);
- });
- });