Travis build: 887
This commit is contained in:
@ -5,12 +5,12 @@ Returns the `n` maximum elements from the provided array. If `n` is greater than
|
||||
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
|
||||
```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]
|
||||
```js
|
||||
maxN([1, 2, 3]); // [3]
|
||||
maxN([1, 2, 3], 2); // [3,2]
|
||||
maxN([1, 2, 3], 4); // [3,2,1]
|
||||
```
|
||||
|
||||
@ -5,12 +5,11 @@ Returns the `n` minimum elements from the provided array. If `n` is greater than
|
||||
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
|
||||
```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]
|
||||
```js
|
||||
minN([1, 2, 3]); // [1]
|
||||
minN([1, 2, 3], 2); // [1,2]
|
||||
minN([1, 2, 3], 4); // [1,2,3]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user