Skip to content

Commit

Permalink
Don't treat 1 as prime number.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed May 24, 2018
1 parent f0ddaf2 commit 5503cce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/math/primality-test/trialDivision.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5503cce

Please sign in to comment.