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:
Padovan nth number
### 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**: v10.15.1

**Q**: Mention the *Issue Number*! (`e.g. Fixed #8`)
**A**: #46 

- *Give additional information regarding the PR below:*
Added padovan sequence in src by taking reference from fibonacci and required it in src/index.js
------------


Patch:
diff --git a/README.md b/README.md
index a8c2bf7..4f9c84a 100644
--- a/README.md
+++ b/README.md
@@ -16,14 +16,15 @@ Hence, I believe maybe its time for people who are well versed with this particu
 
 You can download the package in your working directory by simply typing in the **terminal** (for Mac/Linux users) or **command prompt** (for Windows users):
 
-```
+```bash
 $ npm install mathball --save
 ```
+
 ## Features
 
 - **Number Checkers** - [isArmstrong][3] - [isAutomorphic][4] - [isKaprekar][23] - [isLucky][24] - [isNeon][5] - [isPalindrome][6] - [isPerfect][27] - [isPrime][7] - [isSmith][26]
 
-- **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [fibonacci][8] - [magic][9] - [smart][25]
+- **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [fibonacci][8] - [magic][9] - [smart][25] - [padovan][41]
 
 - **Mathematical Utilities** - [gcd][10] - [isEven][11] - [isOdd][12] - [lcm][13] - [length][14] - [max][15] - [min][16] - [sort][17] - [sum][18] - [modInv][39] - [rangePrime][7] - [frequency][40]
 
@@ -36,9 +37,9 @@ You can access all the utilities via **mathball** object, `M` (or whatever you e
 ```js
 let M = require('mathball');
 
-console.log(M.isPalindrome(1551))       //true
-console.log(M.isEven(7))		//false
-console.log(M.sum([4, 5, 9]))		//18
+console.log(M.isPalindrome(1551)); //true
+console.log(M.isEven(7)); //false
+console.log(M.sum([4, 5, 9])); //18
 ```
 
 Or, you can directly access an individual function as given below:
@@ -46,7 +47,7 @@ Or, you can directly access an individual function as given below:
 ```js
 let gcd = require('mathball/lib/gcd');
 
-console.log(gcd([12, 18, 24]));		//6
+console.log(gcd([12, 18, 24])); //6
 ```
 
 ## Contribution
@@ -101,3 +102,4 @@ The MIT License 2019 - [Priyabrata Biswas][20].
 [32]: https://github.com/pbiswas101/Mathball/blob/master/src/bell/index.js
 [39]: https://github.com/pbiswas101/Mathball/blob/master/src/modInv/index.js
 [40]: https://github.com/pbiswas101/Mathball/blob/master/src/frequency/index.js
+[41]: https://github.com/pbiswas101/Mathball/blob/master/src/padovan/index.js
diff --git a/src/index.js b/src/index.js
index fa75420..d888fa9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -15,20 +15,21 @@ const bell = require('./bell'),
 	factorial = require('./factorial'),
 	fibonacci = require('./fibonacci'),
 	magic = require('./magic'),
+	padovan = require('./padovan'),
 	smart = require('./smart');
 
 /* Mathematical Utilities */
-const gcd = require('./gcd'),
+const frequency = require('./frequency'),
+  gcd = require('./gcd'),
 	isEven = require('./isEven'),
 	isOdd = require('./isOdd'),
 	lcm = require('./lcm'),
 	length = require('./length'),
 	max = require('./max'),
 	min = require('./min'),
-	sort = require('./sort'),
-	sum = require('./sum'),
 	modInv = require('./modInv'),
-	frequency = require('./frequency');
+	sort = require('./sort'),
+	sum = require('./sum');
 
 /* Helper Methods */
 const performance = require('./performance'),
@@ -42,6 +43,7 @@ module.exports = {
 	catalan: catalan.catalan,
 	factorial: factorial.factorial,
 	fibonacci: fibonacci.fibonacci,
+	padovan: padovan.padovan,
 	gcd,
 	isEven,
 	isOdd,
diff --git a/src/padovan/index.js b/src/padovan/index.js
new file mode 100644
index 0000000..3147530
--- /dev/null
+++ b/src/padovan/index.js
@@ -0,0 +1,24 @@
+/* Padovan Number
+ * Function: padovan()
+ */
+
+const validate = require("../validation/positive-integer");
+
+function pad(num) {
+	let pPrevPrev = 1,
+		pPrev = 1,
+		pCurr = 1,
+		pNext = 1;
+	for (let i = 3; i <= num; i++) {
+		pNext = pPrevPrev + pPrev;
+		pPrevPrev = pPrev;
+		pPrev = pCurr;
+		pCurr = pNext;
+	}
+	return pNext;
+}
+
+exports.padovan = num => {
+	validate(num, "padovan");
+	return pad(num);
+};


Test patch:
diff --git a/test/padovan-spec.js b/test/padovan-spec.js
new file mode 100644
index 0000000..cb314ad
--- /dev/null
+++ b/test/padovan-spec.js
@@ -0,0 +1,36 @@
+const assert = require("assert"),
+	padovan = require("../src/padovan").padovan;
+
+describe("[Function: padovan]", () => {
+	it("should be a function", () => {
+		assert.strictEqual(typeof padovan, "function");
+	});
+
+	it("should return a number when a positive integer is passed", () => {
+		assert.strictEqual(typeof padovan(1), "number");
+	});
+
+	it("should return '4' when '6' is passed", () => {
+		assert.strictEqual(padovan(6), 4);
+	});
+
+	it("should return '49' when '15' is passed", () => {
+		assert.strictEqual(padovan(15), 49);
+	});
+
+	it("should throw an error when a negative number is passed", () => {
+		assert.throws(() => padovan(-20), TypeError);
+	});
+
+	it("should throw an error when a floating point is passed", () => {
+		assert.throws(() => padovan(31.101996), TypeError);
+	});
+
+	it("should throw an error when a string is passed", () => {
+		assert.throws(() => padovan("31"), TypeError);
+	});
+
+	it("should throw an error when no arguments passed", () => {
+		assert.throws(() => padovan(), TypeError);
+	});
+});