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:
Add range palin
### 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**:#76

- *Give additional information regarding the PR below:*

------------


Patch:
diff --git a/README.md b/README.md
index 4b4ea7a..f81962f 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ $ npm install mathball --save
 
 - **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [nCr][48] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25]
 
-- **Range of Numbers** - [rangePrime][7] - [rangeFibonacci][8]
+- **Range of Numbers** - [rangePrime][7] - [rangeFibonacci][8] - [rangePalindrome][6]
 
 - **Mathematical Utilities** - [Complex][49] - [frequency][40] - [gcd][10] - [isEven][11] - [isOdd][12] - [lcm][13] - [length][14] - [max][15] - [min][16] - [modInv][39] - [nCr][48] - [pow][46] - [sort][17] - [sum][18] - [toDegrees][50] - [toRadians][51]
 
diff --git a/src/index.js b/src/index.js
index 8527255..327524f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -71,6 +71,7 @@ module.exports = {
 	nCr,
 	isNeon: neon.isNeon,
 	isPalindrome: palindrome.isPalindrome,
+	rangePalindrome:palindrome.rangePalindrome,
 	isPerfect: perfect.isPerfect,
 	isFrugal: isFrugal.isFrugal,
 	performance,
diff --git a/src/palindrome/index.js b/src/palindrome/index.js
index 0767353..b62c841 100644
--- a/src/palindrome/index.js
+++ b/src/palindrome/index.js
@@ -1,5 +1,6 @@
 /* Palindromic Number
  * Function: isPalindrome()
+ * Function: rangePal() --> to return all palindromic numbers from 0 to end
  */
 
 const validate = require('../validation/non-negative-integer');
@@ -8,3 +9,32 @@ exports.isPalindrome = num => {
 	validate(num, 'isPalindrome');
 	return num == num.toString().split('').reverse().join('');
 };
+
+exports.rangePalindrome = (start, end) => {
+	validate(start, 'rangePal');
+	validate(end, 'rangePal');
+	
+	if(start > end)
+	{
+		throw new TypeError(
+			`Starting number must be smaller than the ending number!!\n`
+		);
+	}
+	let palinList = [], lim = 0;
+	
+	lim = (end < 10)? end : start;
+
+	for(let i = start; i < lim; i++)
+	{
+		palinList.push(i);
+	}
+
+	for(let i = lim; i < end; i++)
+	{
+		if(i.toString() === i.toString().split('').reverse().join('')){
+			palinList.push(i);
+		}
+	}
+
+	return palinList;
+};


Test patch:
diff --git a/test/palindrome-spec.js b/test/palindrome-spec.js
index ab5fc76..d2eeb95 100644
--- a/test/palindrome-spec.js
+++ b/test/palindrome-spec.js
@@ -1,5 +1,6 @@
 const assert = require('assert'),
-	isPalindrome = require('../src/palindrome').isPalindrome;
+	isPalindrome = require('../src/palindrome').isPalindrome,
+	rangePalindrome = require('../src/palindrome').rangePalindrome;
 
 describe('[Function: isPalindrome]', () => {
 
@@ -36,3 +37,47 @@ describe('[Function: isPalindrome]', () => {
 	});
 
 });
+
+describe('[Function: rangePalindrome]', () => {
+
+	it('should be a function', () => {
+		assert.strictEqual(typeof rangePalindrome, 'function');
+	});
+
+	it('should return a object when a non-negative integers are passed', () => {
+		assert.strictEqual(typeof rangePalindrome(1,5), 'object');
+	});
+
+	it('should throw an error when a negative number is passed', () => {
+		assert.throws(() => rangePalindrome(-20), TypeError);
+	});
+
+	it('should throw an error when a lower limit is larger than upper limit', () => {
+		assert.throws(() => rangePalindrome(25,20), TypeError);
+	});
+
+	it('should throw an error when a negative number is passed', () => {
+		assert.throws(() => rangePalindrome(15,-20), TypeError);
+	});
+
+	it('should throw an error when a floating point is passed', () => {
+		assert.throws(() => rangePalindrome(31.101996), TypeError);
+	});
+
+	it('should throw an error when a string is passed', () => {
+		assert.throws(() => rangePalindrome('31'), TypeError);
+	});
+
+	it('should throw an error when no arguments passed', () => {
+		assert.throws(() => rangePalindrome(), TypeError);
+	});
+
+	it('should throw an error when one argument is passed', () => {
+		assert.throws(() => rangePalindrome(5), TypeError);
+	});
+
+	it('should return \'[0,1,2,3,4,5,6,7,8,9,11]\' when \'0, 18\' are passed', () => {
+		assert.deepEqual(rangePalindrome(0,18), [0,1,2,3,4,5,6,7,8,9,11]);
+	});
+
+});
\ No newline at end of file