Last active
December 3, 2017 19:49
-
-
Save fhinkel/2876ea53ab539c8d7c8e7026d5cdec72 to your computer and use it in GitHub Desktop.
Revisions
-
fhinkel revised this gist
Dec 3, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ function isPrime(p) { const upper = Math.sqrt(p); for(let i = 2; i <= upper; i++) { if (p % i === 0 ) { return false; } -
fhinkel created this gist
Dec 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ function isPrime(p) { for(let i = 2; i <= Math.sqrt(p); i++) { if (p % i === 0 ) { return false; } } return true; } // Return n-th prime function prime(n) { if (n < 1) { throw Error("n too small: " + n); } let count = 0; let result = 1; while(count < n) { result++; if (isPrime(result)) { count++; } } return result; } module.exports = { prime };