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:
Triangular Numbers
### Do the checklist before submitting the PR:

- [:heavy_check_mark:] Have you read the guidelines mentioned in **CONTRIBUTING.md**?
- [:heavy_check_mark:] 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.10.1

**Q**: Mention the *Issue Number*! (`e.g. Fixed #8`)
**A**:#93

- *Give additional information regarding the PR below:*

------------


Patch:
diff --git a/README.md b/README.md
index 22f8d97..993108b 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ $ npm install mathball --save
 
 - **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [nCr][48] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25] - [ugly][56]
 
+- **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [fibonacci][8] - [magic][9] - [smart][25] - [padovan][41] - [triangular][93]
+
 - **Range of Numbers** - [rangePrime][7] - [rangeFibonacci][8] - [rangePalindrome][6]
 
 - **Mathematical Utilities** - [Complex][49] - [frequency][40] - [gcd][10] - [getAllPerm][55] - [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]
@@ -121,5 +123,6 @@ The MIT License 2019 - [Priyabrata Biswas][20].
 [53]: https://github.com/pbiswas101/Mathball/blob/master/src/stack/index.js
 [54]: https://github.com/pbiswas101/Mathball/blob/master/src/isHoax/index.js
 [55]: https://github.com/pbiswas101/Mathball/blob/master/src/permutation/index.js
+[93]: https://github.com/pbiswas101/Mathball/blob/master/src/triangular/index.js
 [56]: https://github.com/pbiswas101/Mathball/blob/master/src/ugly/index.js
 [57]: https://github.com/pbiswas101/Mathball/blob/master/src/graph/index.js
diff --git a/src/index.js b/src/index.js
index 90019b0..e148d21 100644
--- a/src/index.js
+++ b/src/index.js
@@ -24,6 +24,7 @@ const bell = require('./bell'),
 	nCr = require('./nCr'),
 	padovan = require('./padovan'),
 	smart = require('./smart'),
+	triangular = require('./triangular'),
 	{ ugly } = require('./ugly');
 
 /* Mathematical Utilities */
@@ -102,5 +103,6 @@ module.exports = {
 	rangeFibonacci: fibonacci.rangeFibonacci,
 	Complex,
 	isHoax,
-	ugly
+	ugly,
+	triangular: triangular.triangular
 };
diff --git a/src/triangular/index.js b/src/triangular/index.js
new file mode 100644
index 0000000..79943e9
--- /dev/null
+++ b/src/triangular/index.js
@@ -0,0 +1,21 @@
+/*Triangular Number
+*Function: M.triangular()
+*/
+
+const validate = require('../validation/positive-integer');
+
+const triangular = (n) => {
+	let sum = 0;
+	for(let i = 1; sum <= n; i++){
+		sum += i;
+		if(sum === n){
+			return true;}
+			
+	}
+	return false;
+};
+
+exports.triangular = (n) => {
+	validate(n, 'triangular');
+	return triangular(n);
+};


Test patch:
diff --git a/test/triangular-spec.js b/test/triangular-spec.js
new file mode 100644
index 0000000..83f22e0
--- /dev/null
+++ b/test/triangular-spec.js
@@ -0,0 +1,28 @@
+const assert = require('assert'),
+triangular = require('../src/triangular').triangular;
+
+describe('[Function: triangular]', () => {
+	it('should be a function', () => {
+		assert.strictEqual(typeof triangular, 'function');
+	});
+
+	it('should return true when 55 is passed', () => {
+		assert.strictEqual(triangular(55), true);
+	});
+
+	it('should return false when 40 is passed', () => {
+		assert.strictEqual(triangular(40), false);
+	});
+
+	it('should throw an error when a boolean is passed', () => {
+		assert.throws(() => triangular(true), TypeError);
+	});
+
+	it('should throw an error if a string is passed', () => {
+		assert.throws(() => triangular('hello'), TypeError);
+	});
+
+	it('should throw an error when a negative number is passed', () => {
+		assert.throws(() => triangular(-4), TypeError);
+	});
+});