diff --git a/README.md b/README.md
index 68e24214e..53d1142d2 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@

# 30 seconds of code
-[](https://github.com/Chalarangelo/30-seconds-of-code/blob/master/LICENSE) [](https://gitter.im/30-seconds-of-code/Lobby) [](http://makeapullrequest.com) [](https://travis-ci.org/Chalarangelo/30-seconds-of-code) [](https://insight.io/github.com/Chalarangelo/30-seconds-of-code/tree/master/?source=0) [](https://github.com/Flet/semistandard)
+
+[](https://github.com/Chalarangelo/30-seconds-of-code/blob/master/LICENSE) [](https://gitter.im/30-seconds-of-code/Lobby) [](http://makeapullrequest.com) [](https://travis-ci.org/Chalarangelo/30-seconds-of-code) [](https://insight.io/github.com/Chalarangelo/30-seconds-of-code/tree/master/?source=0) [](https://github.com/Flet/semistandard) [](https://www.producthunt.com/posts/30-seconds-of-code)
+
> Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.
@@ -283,6 +285,16 @@
+### _Uncategorized_
+
+
+View contents
+
+* [`maxN`](#maxn)
+* [`minN`](#minn)
+
+
+
---
## 🔌 Adapter
@@ -3253,7 +3265,7 @@ round(1.005, 2); // 1.01
### solveRPN
Solves the given mathematical expression in [reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation).
-Throws appropriate errors if there are unrecognized symbols or the expression is wrong.
+Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- `+`,`-`,`*`,`/`,`^`,`**` (`^`&`**` are the exponential symbols and are same). This snippet does not supports any unary operators.
Use a dictionary, `OPERATORS` to specify each operator's matching mathematical operation.
Use `String.replace()` with a regular expression to replace `^` with `**`, `String.split()` to tokenize the string and `Array.filter()` to remove empty tokens.
@@ -3340,7 +3352,7 @@ standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (popu
### sum
-Returns the sum of an of two or more numbers/arrays.
+Returns the sum of two or more numbers/arrays.
Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`.
@@ -5127,6 +5139,47 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents)
+---
+ ## _Uncategorized_
+
+### maxN
+
+Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length than return the original array(sorted in descending order).
+
+Sort's the array's shallow copy in descending order and returns the first n elements
+
+Skip the second argument to get a single element(in the form of a array)
+```js
+const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
+```
+
+```js
+maxN([1, 2, 3]); // [3]
+maxN([1, 2, 3], 2); // [3,2]
+maxN([1, 2, 3], 4); // [3,2,1]
+```
+
+ [⬆ back to top](#table-of-contents)
+
+
+### minN
+
+Returns the `n` minimum elements from the provided array. If `n` is greater than or equal to the provided array's length than return the original array(sorted in ascending order).
+
+Sort's the array's shallow copy in ascending order and returns the first n elements
+
+Skip the second argument to get a single element(in the form of a array)
+```js
+const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
+```
+```js
+minN([1, 2, 3]); // [1]
+minN([1, 2, 3], 2); // [1,2]
+minN([1, 2, 3], 4); // [1,2,3]
+```
+
+ [⬆ back to top](#table-of-contents)
+
## Collaborators
diff --git a/docs/index.html b/docs/index.html
index 92f670e5d..82eab6aae 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -59,7 +59,7 @@
wrapper.appendChild(box);
box.appendChild(el);
});
- }
30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
Adapter
call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals to round to an integer.
Solves the given mathematical expression in reverse polish notation. Throws appropriate errors if there are unrecognized symbols or the expression is wrong.
Use a dictionary, OPERATORS to specify each operator's matching mathematical operation. Use String.replace() with a regular expression to replace ^ with **, String.split() to tokenize the string and Array.filter() to remove empty tokens. Use Array.forEach() to parse each symbol, evaluate it as a numeric value or operator and solve the mathematical expression. Numeric values are converted to floating point numbers and pushed to a stack, while operators are evaluated using the OPERATORS dictionary and pop elements from the stack to apply operations.
const solveRPN = rpn => {
+
solveRPN
Solves the given mathematical expression in reverse polish notation. Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- +,-,*,/,^,** (^&** are the exponential symbols and are same). This snippet does not supports any unary operators.
Use a dictionary, OPERATORS to specify each operator's matching mathematical operation. Use String.replace() with a regular expression to replace ^ with **, String.split() to tokenize the string and Array.filter() to remove empty tokens. Use Array.forEach() to parse each symbol, evaluate it as a numeric value or operator and solve the mathematical expression. Numeric values are converted to floating point numbers and pushed to a stack, while operators are evaluated using the OPERATORS dictionary and pop elements from the stack to apply operations.
const solveRPN = rpn => {
const OPERATORS = {
'*': (a, b) => a * b,
'+': (a, b) => a + b,
@@ -732,7 +732,7 @@ solveRPN('2 3 ^'); //8
};
Returns the sum of the powers of all the numbers from start to end (both inclusive).
Use Array.fill() to create an array of all the numbers in the target range, Array.map() and the exponent operator (**) to raise them to power and Array.reduce() to add them together. Omit the second argument, power, to use a default power of 2. Omit the third argument, start, to use a default starting value of 1.
Returns the n maximum elements from the provided array. If n is greater than or equal to the provided array's length than return the original array(sorted in descending order).
Sort's the array's shallow copy in descending order and returns the first n elements
Skip the second argument to get a single element(in the form of a array)
const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
+
Returns the n minimum elements from the provided array. If n is greater than or equal to the provided array's length than return the original array(sorted in ascending order).
Sort's the array's shallow copy in ascending order and returns the first n elements
Skip the second argument to get a single element(in the form of a array)
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
+
\ No newline at end of file
diff --git a/snippets/initializeArrayWithRange.md b/snippets/initializeArrayWithRange.md
index 22b126ad8..7c803aed0 100644
--- a/snippets/initializeArrayWithRange.md
+++ b/snippets/initializeArrayWithRange.md
@@ -1,16 +1,18 @@
### initializeArrayWithRange
-Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive.
+Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive with there common difference `step`.
-Use `Array((end + 1) - start)` to create an array of the desired length, `Array.map()` to fill with the desired values in a range.
+Use `Array(Math.ceil((end+1-start)/step)` to create an array of the desired length(the amounts of elements is equal to `(end-start)/step` or `(end+1-start)/step` for inclusive end), `Array.map()` to fill with the desired values in a range.
You can omit `start` to use a default value of `0`.
-
+You can omit `step` to use a default value of `1`.
+
```js
-const initializeArrayWithRange = (end, start = 0) =>
- Array.from({ length: end + 1 - start }).map((v, i) => i + start);
+const initializeArrayWithRange = (end, start = 0,step = 1) =>
+ Array.from({length:Math.ceil((end + 1 - start)/step)}).map((v, i) => (i * step) + start);
```
```js
initializeArrayWithRange(5); // [0,1,2,3,4,5]
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
+initializeArrayWithRange(9,0,2); //[0,2,4,6,8]
```
diff --git a/snippets/maxN.md b/snippets/maxN.md
new file mode 100644
index 000000000..efc9e5052
--- /dev/null
+++ b/snippets/maxN.md
@@ -0,0 +1,16 @@
+### maxN
+
+Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length than return the original array(sorted in descending order).
+
+Sort's the array's shallow copy in descending order and returns the first n elements
+
+Skip the second argument to get a single element(in the form of a array)
+```js
+const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
+```
+
+```js
+maxN([1, 2, 3]); // [3]
+maxN([1, 2, 3], 2); // [3,2]
+maxN([1, 2, 3], 4); // [3,2,1]
+```
diff --git a/snippets/minN.md b/snippets/minN.md
new file mode 100644
index 000000000..2cee5b091
--- /dev/null
+++ b/snippets/minN.md
@@ -0,0 +1,15 @@
+### minN
+
+Returns the `n` minimum elements from the provided array. If `n` is greater than or equal to the provided array's length than return the original array(sorted in ascending order).
+
+Sort's the array's shallow copy in ascending order and returns the first n elements
+
+Skip the second argument to get a single element(in the form of a array)
+```js
+const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
+```
+```js
+minN([1, 2, 3]); // [1]
+minN([1, 2, 3], 2); // [1,2]
+minN([1, 2, 3], 4); // [1,2,3]
+```
diff --git a/snippets/solveRPN.md b/snippets/solveRPN.md
index 099be512a..87a1fee3f 100644
--- a/snippets/solveRPN.md
+++ b/snippets/solveRPN.md
@@ -1,7 +1,7 @@
### solveRPN
Solves the given mathematical expression in [reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation).
-Throws appropriate errors if there are unrecognized symbols or the expression is wrong.
+Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- `+`,`-`,`*`,`/`,`^`,`**` (`^`&`**` are the exponential symbols and are same). This snippet does not supports any unary operators.
Use a dictionary, `OPERATORS` to specify each operator's matching mathematical operation.
Use `String.replace()` with a regular expression to replace `^` with `**`, `String.split()` to tokenize the string and `Array.filter()` to remove empty tokens.
diff --git a/snippets/sum.md b/snippets/sum.md
index c6894b6a8..a69aa3d4f 100644
--- a/snippets/sum.md
+++ b/snippets/sum.md
@@ -1,6 +1,6 @@
### sum
-Returns the sum of an of two or more numbers/arrays.
+Returns the sum of two or more numbers/arrays.
Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`.
diff --git a/static-parts/README-start.md b/static-parts/README-start.md
index 02cd09f4f..a3a94d299 100644
--- a/static-parts/README-start.md
+++ b/static-parts/README-start.md
@@ -1,7 +1,9 @@

# 30 seconds of code
-[](https://github.com/Chalarangelo/30-seconds-of-code/blob/master/LICENSE) [](https://gitter.im/30-seconds-of-code/Lobby) [](http://makeapullrequest.com) [](https://travis-ci.org/Chalarangelo/30-seconds-of-code) [](https://insight.io/github.com/Chalarangelo/30-seconds-of-code/tree/master/?source=0) [](https://github.com/Flet/semistandard)
+
+[](https://github.com/Chalarangelo/30-seconds-of-code/blob/master/LICENSE) [](https://gitter.im/30-seconds-of-code/Lobby) [](http://makeapullrequest.com) [](https://travis-ci.org/Chalarangelo/30-seconds-of-code) [](https://insight.io/github.com/Chalarangelo/30-seconds-of-code/tree/master/?source=0) [](https://github.com/Flet/semistandard) [](https://www.producthunt.com/posts/30-seconds-of-code)
+
> Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.