Write a program to check is the number simple.
It can receive either negative or positive numbers, integer and not integer, simple and not simple.
It should return true if the given number is actually simple (2, 3, 5, 7...)
export const checkIsNumberSimple = (number: number) => {
// Check if the number is integer
if (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;
};
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { checkIsNumberSimple } from "./solution";
// TODO Add your tests here
describe("Simple numbers", function() {
it("should not be negative numbers", function() {
assert.strictEqual(checkIsNumberSimple(-1), false);
});
it("should be integer numbers", function() {
assert.strictEqual(checkIsNumberSimple(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);
});
});