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:
range function added
### Do the checklist before submitting the PR:

- [x] Have you read the guidelines mentioned in **CONTRIBUTING.md**?
- [] Have you squashed your commits?

**Q**: What version of *Node.js* you've used in the project? (`e.g. Node v10.11.0`)
**A**: Node v10.14.2

**Q**: Mention the *Issue Number*! (`e.g. Fixed #8`)
**A**: Fixed#110

- *Give additional information regarding the PR below:*

------------
range function for rangefibonacci added

Patch:
diff --git a/README.md b/README.md
index 18f1f2d..7ee5809 100644
--- a/README.md
+++ b/README.md
@@ -22,11 +22,11 @@ $ 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] - [isStormer][52] -[isHoax][54]
+- **Number Checkers** - [isArmstrong][3] - [isAutomorphic][4] - [isCarmichael][43] - [isDeficient][42] - [isFrugal][47] - [isHarshad][45] - [isKaprekar][23] - [isLucky][24] - [isNeon][5] - [isPalindrome][6] - [isPerfect][27] - [M.check('prime')(Number)][7] - [isSmith][26] - [isStormer][52] -[isHoax][54]
 
-- **Find nth Number** - [bell][32] - [catalan][22] - [fibonacci][8] - [find][21] - [magic][9] - [nCr][48] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25] - [triangular][93] - [ugly][56]
+- **Find nth Number** - [bell][32] - [catalan][22] - [fibonacci][8] - [find][21] - [magic][9] - [nCr][48] - [magic][9] - [padovan][41] - [smart][25] - [triangular][93] - [ugly][56]
 
-- **Range of Numbers** - [rangePrime][7] - [rangeFibonacci][8] - [rangePalindrome][6]
+- **Range of Numbers** - [rangePrime][7] - [range][66] - [rangePalindrome][6]
 
 - **Mathematical Utilities** - [Complex][49] - [frequency][40] - [gcd][10] - [getAllPerm][55] - [isEven][11] - [isOdd][12] - [lcm][13] - [length][14] - [max][15] - [median][64] - [min][16] - [modInv][39] - [nCr][48] - [pow][46] - [sort][17] - [sum][18] - [toDegrees][50] - [toRadians][51] - [matrixMultiply][58] - [matrixExpo][59] - [matrixChain][60] - [count][61] - [avg][62] - [findPrimeFactors][63] - [phi][67]
 
@@ -131,4 +131,5 @@ The MIT License 2019 - [Priyabrata Biswas][20].
 [62]: https://github.com/pbiswas101/Mathball/blob/master/src/avg/index.js
 [63]: https://github.com/pbiswas101/Mathball/blob/master/src/primefactor/index.js
 [64]: https://github.com/pbiswas101/Mathball/blob/master/src/median/index.js
-[67]: https://github.com/pbiswas101/Mathball/blob/master/src/totient/index.js
\ No newline at end of file
+[66]: https://github.com/pbiswas101/Mathball/blob/master/src/range/index.js
+[67]: https://github.com/pbiswas101/Mathball/blob/master/src/totient/index.js
diff --git a/src/carmichael/index.js b/src/carmichael/index.js
index 130ee8e..e2c9490 100644
--- a/src/carmichael/index.js
+++ b/src/carmichael/index.js
@@ -3,7 +3,7 @@
 */
 
 const validate = require('../validation/positive-integer');
-const prime = require('../prime');
+const prime = require('../prime').check;
 
 function squarefree(i){
 	for(let k = 2; (k <= Math.sqrt(i) && i % k !== 0 && i/k % k !== 0); k++){
@@ -15,7 +15,7 @@ function isCarmichael(n){
 	let c = 0;
 	for(let i = 1; i <= n; i++){
 		if(n % i == 0){
-			if(prime.isPrime(i) && ((n-1) % (i-1) == 0)){
+			if(prime(i) && ((n-1) % (i-1) == 0)){
 				c++;
 				if(c >= 3 && i % 2 != 0 && squarefree(i)){
 					return true;
diff --git a/src/check/index.js b/src/check/index.js
new file mode 100644
index 0000000..6f4eb42
--- /dev/null
+++ b/src/check/index.js
@@ -0,0 +1,3 @@
+module.exports = arg => {
+  return require(`../${arg}`).check;
+};
\ No newline at end of file
diff --git a/src/fibonacci/index.js b/src/fibonacci/index.js
index 5831955..5f948c9 100644
--- a/src/fibonacci/index.js
+++ b/src/fibonacci/index.js
@@ -38,7 +38,7 @@ const rangeFib = num => {
 	return rangeArr;
 };
 
-exports.rangeFibonacci = num => {
+exports.range = num => {
 	validate(num, 'rangeFibonacci');
 	return rangeFib(num);
 };
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index 07c4175..aaf2145 100644
--- a/src/index.js
+++ b/src/index.js
@@ -13,7 +13,8 @@ const armstrong = require('./armstrong'),
 	isFrugal = require('./isFrugal'),
 	isStormer = require('./isStormer'),
 	carmichael = require('./carmichael'),
-	{ isHoax } = require('./isHoax');
+	{ isHoax } = require('./isHoax'),
+	check = require('./check');
 
 /* Find nth Number */
 const bell = require('./bell'),
@@ -25,6 +26,7 @@ const bell = require('./bell'),
 	padovan = require('./padovan'),
 	smart = require('./smart'),
 	triangular = require('./triangular'),
+	range = require('./range'),
 	{ ugly } = require('./ugly');
 
 /* Mathematical Utilities */
@@ -98,7 +100,6 @@ module.exports = {
 	pipe,
 	pow,
 	phi: totient.phi,
-	isPrime: prime.isPrime,
 	isStormer: isStormer.isStormer,
 	rangePrime: prime.rangePrime,
 	smart: smart.smart,
@@ -116,9 +117,10 @@ module.exports = {
 	Stack,
 	Graph,
 	isCarmichael: carmichael.isCarmichael,
-	rangeFibonacci: fibonacci.rangeFibonacci,
+	range,
 	Complex,
 	isHoax,
 	ugly,
-	triangular: triangular.triangular
+	triangular: triangular.triangular,
+	check
 };
diff --git a/src/prime/index.js b/src/prime/index.js
index 5521331..176fd64 100644
--- a/src/prime/index.js
+++ b/src/prime/index.js
@@ -4,7 +4,7 @@
 
 const validate = require('../validation/positive-integer');
 
-exports.isPrime = num => {
+exports.check = num => {
 	validate(num, 'isPrime');
   if (num === 2 || num === 3) { return true; }
   if (num < 2 || num % 2 === 0) { return false; }
diff --git a/src/range/index.js b/src/range/index.js
new file mode 100644
index 0000000..d811212
--- /dev/null
+++ b/src/range/index.js
@@ -0,0 +1,8 @@
+/* Function: range() */
+
+const validate = require('../validation/string');
+
+module.exports = arg => {
+    validate(arg,'range');
+    return require(`../${arg}`).range;
+};


Test patch:
diff --git a/test/check-spec.js b/test/check-spec.js
new file mode 100644
index 0000000..04b6b62
--- /dev/null
+++ b/test/check-spec.js
@@ -0,0 +1,12 @@
+const assert = require("assert"),
+	check = require("../src/check");
+
+describe("[Function: check]", () => {
+	it("should be a function", () => {
+		assert.strictEqual(typeof check, "function");
+  });
+
+	it("should return `true` when called `prime` with 2 as an argument", () => {
+		assert.strictEqual(check('prime')(2), true);
+  });
+});
diff --git a/test/fibonacci-spec.js b/test/fibonacci-spec.js
index aa51f3b..0fc873f 100644
--- a/test/fibonacci-spec.js
+++ b/test/fibonacci-spec.js
@@ -1,6 +1,6 @@
 const assert = require('assert'),
 	fibonacci = require('../src/fibonacci').fibonacci,
-	rangeFibonacci = require('../src/fibonacci').rangeFibonacci;
+	rangeFibonacci = require('../src/fibonacci').range;
 
 describe('[Function: fibonacci]', () => {
 
diff --git a/test/prime-spec.js b/test/prime-spec.js
index 88957d0..dfb44d5 100644
--- a/test/prime-spec.js
+++ b/test/prime-spec.js
@@ -1,6 +1,6 @@
 const assert = require('assert'),
 	prime = require('../src/prime'),
-	isPrime = prime.isPrime,
+	isPrime = prime.check,
 	rangePrime = prime.rangePrime;
 
 describe('[Function: isPrime]', () => {
diff --git a/test/range-spec.js b/test/range-spec.js
new file mode 100644
index 0000000..fc6be83
--- /dev/null
+++ b/test/range-spec.js
@@ -0,0 +1,36 @@
+const assert = require('assert'),
+	range = require('../src/range');
+
+
+describe('[Function: range]', () => {
+
+	it('should be a function', () => {
+		assert.strictEqual(typeof range, 'function');
+	});
+
+	it('should return `[0, 1, 1]` when fibonacci is passed as arg & 1 is passed as arg to fibonacci', () => {
+		assert.deepEqual(range('fibonacci')(1), [0, 1, 1]);
+	});
+
+	it('should return `[0, 1, 1, 2]` when fibonacci is passed as arg & 2 is passed as arg to fibonacci', () => {
+		assert.deepEqual(range('fibonacci')(2), [0, 1, 1, 2]);
+    });
+    
+    it('should throw an error when no arguments passed', () => {
+        assert.throws(() => range(), TypeError);
+    });
+
+    it('should throw an error when a number is passed', () => {
+        assert.throws(() => range(31), TypeError);
+    });
+
+    it('should throw an error when a negative number is passed', () => {
+        assert.throws(() => range(-20), TypeError);
+    });
+
+    it('should throw an error when a floating point is passed', () => {
+        assert.throws(() => range(31.101996), TypeError);
+    });
+
+
+});
\ No newline at end of file