Repository: pbiswas101/Mathball
Pull request #13 (2019-01-28 12:01:50)

Added smart number function
**Q**: What version of *Node.js* you've used in the project?
**A**: `e.g. Node v10.12.0`

**Q**: Mention the *Issue Number*!
**A**: `e.g. #12`


codecov-io: # [Codecov](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=h1) Report
> Merging [#13](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=desc) into [master](https://codecov.io/gh/pbiswas101/Mathball/commit/65f84df8e0228331291c31cd42f334b07daed07e?src=pr&el=desc) will **increase** coverage by `0.26%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pbiswas101/Mathball/pull/13/graphs/tree.svg?width=650&token=d91h0D3j17&height=150&src=pr)](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #13      +/-   ##
==========================================
+ Coverage   97.07%   97.33%   +0.26%     
==========================================
  Files          21       22       +1     
  Lines         205      225      +20     
==========================================
+ Hits          199      219      +20     
  Misses          6        6
```


| [Impacted Files](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://codecov.io/gh/pbiswas101/Mathball/pull/13/diff?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `100% <100%> (ø)` | :arrow_up: |
| [src/smart/index.js](https://codecov.io/gh/pbiswas101/Mathball/pull/13/diff?src=pr&el=tree#diff-c3JjL3NtYXJ0L2luZGV4Lmpz) | `100% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=footer). Last update [65f84df...1d9cf00](https://codecov.io/gh/pbiswas101/Mathball/pull/13?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/index.js b/src/index.js
index 84dba62..af09cc4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,7 +10,8 @@ const armstrong = require("./armstrong"),
 	factorial = require("./factorial"),
 	catalan = require("./catalan"),
 	kaprekar = require("./kaprekar"),
-	lucky = require("./lucky");
+	lucky = require("./lucky"),
+	smart = require("./smart");
 
 /* Mathematical Utilities */
 
@@ -38,6 +39,7 @@ module.exports = {
 	catalan: catalan.catalan,
 	isKaprekar: kaprekar.isKaprekar,
 	isLucky: lucky.isLucky,
+	smart: smart.smart,
 	gcd,
 	isEven,
 	isOdd,
diff --git a/src/smart/index.js b/src/smart/index.js
new file mode 100644
index 0000000..93556af
--- /dev/null
+++ b/src/smart/index.js
@@ -0,0 +1,36 @@
+/* Smart Number
+ * Function: smart()
+ */
+const sort = require("../sort");
+function validate(arg) {
+	if (typeof arg != "number" || arg < 1 || !Number.isInteger(arg)) {
+		throw new TypeError(
+			`Invalid argument recieved: ${JSON.stringify(
+				arg
+			)}\n'smart()' only accept a positive integer!\n`
+		);
+	}
+}
+
+exports.smart = num => {
+	validate(num);
+	const size = 3000;
+	var primes = new Array(size);
+	for (var i = 0; i < size; i++) {
+		primes[i] = 0;
+	}
+	var result = new Array();
+	for (var i = 2; i < size; i++) {
+		if (primes[i] === 0) {
+			primes[i] = 1;
+			for (var j = i * 2; j < size; j = j + i) {
+				primes[j] = primes[j] - 1;
+				if (primes[j] + 3 === 0) {
+					result.push(j);
+				}
+			}
+		}
+	}
+	sort(result);
+	return result[num - 1];
+};


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