Update minN.md

This commit is contained in:
Rohit Tanwar
2018-01-03 11:40:39 +05:30
committed by GitHub
parent bfb21ff71a
commit 231ff2331b

View File

@ -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)
``` js
const minN = (arr,n = 1) => {
let rra = [...arr].sort((a,b) => a-b)
return rra.splice(0,n)
}
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
```
``` js
maxN([1,2,3]); // [1]
maxN([1,2,3],2); // [1,2]
maxN([1,2,3],4); // [1,2,3]
minN([1,2,3]); // [1]
minN([1,2,3],2); // [1,2]
minN([1,2,3],4); // [1,2,3]
```