Update minN.md
This commit is contained in:
@ -6,13 +6,11 @@ Sort's the array's shallow copy in ascending order and returns the first n eleme
|
|||||||
|
|
||||||
Skip the second argument to get a single element(in the form of a array)
|
Skip the second argument to get a single element(in the form of a array)
|
||||||
``` js
|
``` js
|
||||||
const minN = (arr,n = 1) => {
|
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
|
||||||
let rra = [...arr].sort((a,b) => a-b)
|
|
||||||
return rra.splice(0,n)
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
``` js
|
``` js
|
||||||
maxN([1,2,3]); // [1]
|
minN([1,2,3]); // [1]
|
||||||
maxN([1,2,3],2); // [1,2]
|
minN([1,2,3],2); // [1,2]
|
||||||
maxN([1,2,3],4); // [1,2,3]
|
minN([1,2,3],4); // [1,2,3]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user