Repository: pbiswas101/Mathball (js)

Issue:
Kaprekar Number
### Do the checklist before filing the issue:

- [ ] Is this something you can **debug and fix**?
- [x] Do you have Node.js and all the relevant dev-dependencies installed?
- [ ] Is this a **feature request** that you can add?

###### NOTE: Provide a clear and concise description of the feature that needs to be added! Or if its a bug, then provide the necessary steps to reproduce it.

- *Give your answer below:*

------------

[Function: **M.isKaprekar()**] needs to be added!
For more info:

https://www.geeksforgeeks.org/kaprekar-number/

*M.isKaprekar()* needs to accept a positive integer and all other arguments passed should throw a type error which needs to be handled gracefully! For error handling, you should refer to how other features like M.isArmstrong() is implemented.

Pull request description:
Adding isStormer() function. Issue #34
### Do the checklist before submitting the PR:

- [x] Have you read the guidelines mentioned in **CONTRIBUTING.md**?
- [x] Have you squashed your commits?

**Q**: What version of *Node.js* you've used in the project? (`e.g. Node v10.11.0`)
**A**:v11.6.0

**Q**: Mention the *Issue Number*! (`e.g. Fixed #8`)
**A**:issue #34 

- *Give additional information regarding the PR below:*

------------


Patch:
diff --git a/README.md b/README.md
index 83a12ae..4b4ea7a 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ $ npm install mathball --save
 
 ## Features
 
-- **Number Checkers** - [isArmstrong][3] - [isAutomorphic][4] - [isCarmichael][43] - [isDeficient][42] - [isFrugal][47] - [isHarshad][45] - [isKaprekar][23] - [isLucky][24] - [isNeon][5] - [isPalindrome][6] - [isPerfect][27] - [isPrime][7] - [isSmith][26]
+- **Number Checkers** - [isArmstrong][3] - [isAutomorphic][4] - [isCarmichael][43] - [isDeficient][42] - [isFrugal][47] - [isHarshad][45] - [isKaprekar][23] - [isLucky][24] - [isNeon][5] - [isPalindrome][6] - [isPerfect][27] - [isPrime][7] - [isSmith][26] - [isStormer][52]
 
 - **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [nCr][48] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25]
 
@@ -116,4 +116,5 @@ The MIT License 2019 - [Priyabrata Biswas][20].
 [48]: https://github.com/pbiswas101/Mathball/blob/master/src/nCr/index.js
 [49]: https://github.com/pbiswas101/Mathball/blob/master/src/complex/index.js
 [50]: https://github.com/pbiswas101/Mathball/blob/master/src/degree/index.js
-[51]: https://github.com/pbiswas101/Mathball/blob/master/src/radian/index.js
\ No newline at end of file
+[51]: https://github.com/pbiswas101/Mathball/blob/master/src/radian/index.js
+[52]: https://github.com/pbiswas101/Mathball/blob/master/src/isStormer/index.js
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index 04e9803..8527255 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,6 +11,7 @@ const armstrong = require('./armstrong'),
 	smith = require('./smith'),
 	isDeficient = require('./isDeficient'),
 	isFrugal = require('./isFrugal'),
+	isStormer = require('./isStormer'),
 	carmichael = require('./carmichael');
 
 /* Find nth Number */
@@ -76,6 +77,7 @@ module.exports = {
 	pipe,
 	pow,
 	isPrime: prime.isPrime,
+	isStormer: isStormer.isStormer,
 	rangePrime: prime.rangePrime,
 	smart: smart.smart,
 	isSmith: smith.isSmith,
diff --git a/src/isStormer/index.js b/src/isStormer/index.js
new file mode 100644
index 0000000..878e17a
--- /dev/null
+++ b/src/isStormer/index.js
@@ -0,0 +1,36 @@
+/* Function to check if number is a stormer number
+    Function name: isStormer()
+*/
+
+const validate = require("../validation/positive-integer");
+
+function maxPrimeFactor(inp){
+
+    let maxPrime = 1;
+    
+    let temp = inp;
+    //testing for all multiples of 2
+    while(temp%2 === 0)
+    {
+        maxPrime = 2;
+        temp = temp / 2;
+    }
+    //for the remaining odd numbers. Note that prime numbers will remove their non-prime multiples BEFORE any
+    //non- prime number can appear
+    for(let i = 3; i <= temp ; i += 2){
+        while(inp%i === 0)
+        {
+            maxPrime = i;   
+            inp = inp / i;
+        }
+    }
+    return maxPrime;
+}
+
+exports.isStormer = n => {
+
+    validate(n, 'isStormer');
+    let largPFactor = maxPrimeFactor((n*n+1));
+    
+    return (largPFactor >= 2*n)?true:false;
+};
\ No newline at end of file


Test patch:
diff --git a/test/stormer-spec.js b/test/stormer-spec.js
new file mode 100644
index 0000000..2cb2f3d
--- /dev/null
+++ b/test/stormer-spec.js
@@ -0,0 +1,45 @@
+const assert = require('assert'),
+        isStormer = require('../src/isStormer').isStormer;
+
+describe('[Function: isStormer', () => {
+
+    it("should be a function", () => {
+		assert.strictEqual(typeof isStormer, "function");
+    });
+
+    it("should throw an error when a string is passed", () => {
+		assert.throws(() => isStormer("31"), TypeError);
+    });
+
+    it("should throw an error when a boolean is passed", () => {
+		assert.throws(() => isStormer(true), TypeError);
+    });
+
+    it("should throw an error when a non-negative number is passed", () => {
+		assert.throws(() => isStormer(-31), TypeError);
+    });
+
+    it("should throw an error when no arguments passed", () => {
+		assert.throws(() => isStormer(), TypeError);
+    });
+    
+    it("should return a boolean", () => {
+		assert.strictEqual(typeof isStormer(5), "boolean");
+    });
+
+    it("should return 'true' when '11' is passed", () => {
+        assert.strictEqual(isStormer(11), true);
+      });
+
+    it("should return 'true' when '1' is passed", () => {
+    assert.strictEqual(isStormer(1), true);
+    });
+
+    it("should return 'true' when '6' is passed", () => {
+        assert.strictEqual(isStormer(6), true);
+    });
+
+    it("should return 'false' when '7' is passed", () => {
+    assert.strictEqual(isStormer(7), false);
+    });
+});      
\ No newline at end of file