mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Add primality tests.
This commit is contained in:
parent
81ca672f5a
commit
f724bd5353
@ -16,6 +16,8 @@ export default function primalityTest(testFunction) {
|
||||
expect(testFunction(4)).toBeFalsy();
|
||||
expect(testFunction(6)).toBeFalsy();
|
||||
expect(testFunction(12)).toBeFalsy();
|
||||
expect(testFunction(14)).toBeFalsy();
|
||||
expect(testFunction(25)).toBeFalsy();
|
||||
expect(testFunction(192)).toBeFalsy();
|
||||
expect(testFunction(200)).toBeFalsy();
|
||||
expect(testFunction(400)).toBeFalsy();
|
||||
|
@ -18,7 +18,7 @@ export default function trialDivision(number) {
|
||||
|
||||
// If there is no dividers up to square root of n then there is no higher dividers as well.
|
||||
const dividerLimit = Math.sqrt(number);
|
||||
for (let divider = 3; divider < dividerLimit; divider += 2) {
|
||||
for (let divider = 3; divider <= dividerLimit; divider += 2) {
|
||||
if (number % divider === 0) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user