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 c5e44d4

Browse files
committed
A few suggestions / modifications / fixes
It seems you've accidentally swapped the implementation and the test file :) The overall comment describing the algorithm (VERY nice doc, by the way) is not "proper" JSdoc => only one leading asterisk. It's generally considered good style to start a comment block (both JSdoc and regular comments) with a single, short sentence. Further down, there were some git hiccups, most likely caused by merge conflicts?
1 parent 3c2fdf7 commit c5e44d4

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

‎Maths/test/FermatPrimalityTest.js renamed to ‎Maths/FermatPrimalityTest.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/**
2-
* The Fermat primality test is a probabilistic test to determine whether a number is a probable prime. It relies on
3-
* Fermat's Little Theorem, which states that if p is prime and a is not divisible by p, then
1+
/*
2+
* The Fermat primality test is a probabilistic test to determine whether a number is a probable prime.
3+
*
4+
* It relies on Fermat's Little Theorem, which states that if p is prime and a is not divisible by p, then
45
*
56
* a^(p - 1) % p = 1
67
*
@@ -53,28 +54,20 @@ const modularExponentiation = (base, exponent, modulus) => {
5354
}
5455

5556
/**
56-
* Test if a given number n is prime or not.
57+
* Test if a given number n is prime or not.
5758
*
5859
* @param {number} n The number to check for primality
5960
* @param {number} numberOfIterations The number of times to apply Fermat's Little Theorem
6061
* @returns True if prime, false otherwise
6162
*/
6263
const fermatPrimeCheck = (n, numberOfIterations) => {
6364
// first check for corner cases
64-
<<<<<<< HEAD
6565
if (n <= 1 || n === 4) return false
66-
=======
67-
if (n <= 1 || n == 4) return false
68-
>>>>>>> 951c7258323a057041c0d128880982ddab303ee5
6966
if (n <= 3) return true // 2 and 3 are included here
7067

7168
for (let i = 0; i < numberOfIterations; i++) {
7269
// pick a random number between 2 and n - 2
73-
<<<<<<< HEAD
7470
const randomNumber = Math.floor(Math.random() * (n - 1 - 2) + 2)
75-
=======
76-
let randomNumber = Math.floor(Math.random() * (n - 1 - 2) + 2)
77-
>>>>>>> 951c7258323a057041c0d128880982ddab303ee5
7871

7972
// if a^(n - 1) % n is different than 1, n is composite
8073
if (modularExponentiation(randomNumber, n - 1, n) !== 1) {

‎Maths/FermatPrimalityTest.test.js renamed to ‎Maths/test/FermatPrimalityTest.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { modularExponentiation,fermatPrimeCheck } from '../FermatPrimalityTest'
1+
import { fermatPrimeCheck,modularExponentiation } from '../FermatPrimalityTest'
22

33
describe('modularExponentiation', () => {
44
it('should give the correct output for all exponentiations', () => {

0 commit comments

Comments
(0)

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