Update maxN.md
This commit is contained in:
@ -6,10 +6,7 @@ Sort's the array's shallow copy in descending order and returns the first n elem
|
|||||||
|
|
||||||
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 maxN = (arr,n = 1) => {
|
const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
|
||||||
let rra = [...arr].sort((a,b) => b-a)
|
|
||||||
return rra.splice(0,n)
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
``` js
|
``` js
|
||||||
|
|||||||
Reference in New Issue
Block a user