Don't treat 1 as prime number.

This commit is contained in:
Oleksii Trekhleb 2018-05-24 16:48:10 +03:00
parent f0ddaf243c
commit 5503cced48
2 changed files with 4 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import trialDivision from '../trialDivision';
* @param {function(n: number)} testFunction
*/
function primalityTest(testFunction) {
expect(testFunction(1)).toBeTruthy();
expect(testFunction(1)).toBeFalsy();
expect(testFunction(2)).toBeTruthy();
expect(testFunction(3)).toBeTruthy();
expect(testFunction(5)).toBeTruthy();

View File

@ -3,11 +3,11 @@
* @return {boolean}
*/
export default function trialDivision(number) {
if (number <= 0) {
// If number is less then one then it isn't prime by definition.
if (number <= 1) {
// If number is less than one then it isn't prime by definition.
return false;
} else if (number <= 3) {
// All numbers from 1 to 3 are prime.
// All numbers from 2 to 3 are prime.
return true;
}