next-prime-generator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/index.js +25 -0
- package/next-prime-generator-1.0.0.tgz +0 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# next-prime
|
|
2
|
+
|
|
3
|
+
A simple JavaScript function that returns the next prime number every time it is called.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install next-prime
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
const nextPrime = require("next-prime");
|
|
14
|
+
|
|
15
|
+
const prime = nextPrime();
|
|
16
|
+
|
|
17
|
+
console.log(prime()); // 2
|
|
18
|
+
console.log(prime()); // 3
|
|
19
|
+
console.log(prime()); // 5
|
|
20
|
+
console.log(prime()); // 7
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function nextPrime() {
|
|
2
|
+
let num = 1;
|
|
3
|
+
|
|
4
|
+
return function () {
|
|
5
|
+
while (true) {
|
|
6
|
+
num++;
|
|
7
|
+
|
|
8
|
+
let isPrime = true;
|
|
9
|
+
|
|
10
|
+
for (let i = 2; i <= Math.sqrt(num); i++) {
|
|
11
|
+
if (num % i === 0) {
|
|
12
|
+
isPrime = false;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (isPrime) {
|
|
18
|
+
return num;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = nextPrime;
|
|
25
|
+
//Make this function available to code that imports this package.
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "next-prime-generator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple function that returns the next prime number",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://gitlab.pal.tech/satvika.nainapally/next-prime.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"prime",
|
|
11
|
+
"number",
|
|
12
|
+
"javascript"
|
|
13
|
+
],
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"author": "Sat",
|
|
16
|
+
"type": "commonjs",
|
|
17
|
+
"main": "index.js",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
|
+
}
|
|
21
|
+
}
|