diff --git a/snippets/maxN.md b/snippets/maxN.md index 8efc46112..e777b1949 100644 --- a/snippets/maxN.md +++ b/snippets/maxN.md @@ -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) ``` js -const maxN = (arr,n = 1) => { - let rra = [...arr].sort((a,b) => b-a) - return rra.splice(0,n) -} +const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); ``` ``` js