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:
nCr method and Test cases implemented (#66)
### 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**: v8.11.4

**Q**: Mention the *Issue Number*! (`e.g. Fixed #8`)
**A**: #66 

- *Give additional information regarding the PR below:*

------------


Patch:
diff --git a/README.md b/README.md
index c30e0bc..e680eb0 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ $ npm install mathball --save
 
 - **Number Checkers** - [isArmstrong][3] - [isAutomorphic][4] - [isCarmichael][43] - [isDeficient][42] - [isKaprekar][23] - [isLucky][24] - [isNeon][5] - [isPalindrome][6] - [isPerfect][27] - [isPrime][7] - [isSmith][26] - [isHarshad][45]
 
-- **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25]
+- **Find nth Number** - [bell][32] - [catalan][22] - [factorial][21] - [nCr][58] - [fibonacci][8] - [magic][9] - [padovan][41] - [smart][25]
 
 - **Range of Numbers** - [rangePrime][7] - [rangeFibonacci][8]
 
@@ -113,3 +113,4 @@ The MIT License 2019 - [Priyabrata Biswas][20].
 [45]: https://github.com/pbiswas101/Mathball/blob/master/src/harshad/index.js
 [46]: https://github.com/pbiswas101/Mathball/blob/master/src/pow/index.js
 [57]: https://github.com/pbiswas101/Mathball/blob/master/src/complex/index.js
+[58]: https://github.com/pbiswas101/Mathball/blob/master/src/nCr/index.js
diff --git a/src/index.js b/src/index.js
index fbef2ed..07239a7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -18,6 +18,7 @@ const bell = require('./bell'),
 	factorial = require('./factorial'),
 	fibonacci = require('./fibonacci'),
 	magic = require('./magic'),
+	nCr = require('./nCr'),
 	padovan = require('./padovan'),
 	smart = require('./smart');
 
@@ -63,6 +64,7 @@ module.exports = {
 	magic: magic.magic,
 	max,
 	min,
+	nCr,
 	isNeon: neon.isNeon,
 	isPalindrome: palindrome.isPalindrome,
 	isPerfect: perfect.isPerfect,
diff --git a/src/nCr/index.js b/src/nCr/index.js
new file mode 100644
index 0000000..65129aa
--- /dev/null
+++ b/src/nCr/index.js
@@ -0,0 +1,36 @@
+/* nCr
+ * Function: nCr()
+ */
+
+const validate = require('../validation/non-negative-integer');
+
+/**
+ *
+ * @param {number, number} number
+ * @returns {number}
+ */
+
+function nCr(number1, number2) {
+
+	let res = 1;
+	let i = 0;
+	if(number2>number1-number2){
+		number2=number1-number2;
+	}
+	for(; i<number2; ++i){
+		res*=(number1-i);
+		res/=(i+1);
+	}
+  return res;
+}
+
+exports.nCr = (number1, number2) => {
+	validate(number1, 'nCr');
+	validate(number2, 'nCr');
+	if(number1 < number2){
+	throw new TypeError(
+		`n >= r condition not satisfied.\n`
+		);
+  }
+ return nCr(number1, number2);
+};


Test patch:
diff --git a/test/nCr-spec.js b/test/nCr-spec.js
new file mode 100644
index 0000000..10e07d6
--- /dev/null
+++ b/test/nCr-spec.js
@@ -0,0 +1,36 @@
+const assert = require('assert'),
+	nCr = require('../src/nCr').nCr;
+
+describe('[Function: nCr]', () => {
+	it('should be a function', () => {
+		assert.strictEqual(typeof nCr, 'function');
+	});
+
+	it('should return 10 when 5 and 2 is passed', () => {
+		assert.strictEqual(nCr(5, 2), 10);
+	});
+
+	it('should return 3 when 3 and 2 is passed', () => {
+		assert.strictEqual(nCr(3, 2), 3);
+	});
+
+	it('should throw an error when a negative number is passed', () => {
+		assert.throws(() => nCr(-2, 1), TypeError);
+	});
+
+	it('should throw an error when first number is smaller than second is passed', () => {
+		assert.throws(() => nCr(2, 3), TypeError);
+	});
+
+	it('should throw an error when a floating point is passed', () => {
+		assert.throws(() => nCr(31.101996, 2), TypeError);
+	});
+
+	it('should throw an error when a string is passed', () => {
+		assert.throws(() => nCr('31', 2), TypeError);
+	});
+
+	it('should throw an error when no arguments passed', () => {
+		assert.throws(() => nCr(), TypeError);
+	});
+});