Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5503cce

Browse files
committed
Don't treat 1 as prime number.
1 parent f0ddaf2 commit 5503cce

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎src/algorithms/math/primality-test/__test__/trialDivision.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import trialDivision from '../trialDivision';
44
* @param {function(n: number)} testFunction
55
*/
66
function primalityTest(testFunction) {
7-
expect(testFunction(1)).toBeTruthy();
7+
expect(testFunction(1)).toBeFalsy();
88
expect(testFunction(2)).toBeTruthy();
99
expect(testFunction(3)).toBeTruthy();
1010
expect(testFunction(5)).toBeTruthy();

‎src/algorithms/math/primality-test/trialDivision.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @return {boolean}
44
*/
55
export default function trialDivision(number) {
6-
if (number <= 0) {
7-
// If number is less then one then it isn't prime by definition.
6+
if (number <= 1) {
7+
// If number is less than one then it isn't prime by definition.
88
return false;
99
} else if (number <= 3) {
10-
// All numbers from 1 to 3 are prime.
10+
// All numbers from 2 to 3 are prime.
1111
return true;
1212
}
1313

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /