From bfb21ff71a3c950ddca6013c65e5c003d05e55f3 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Wed, 3 Jan 2018 11:39:40 +0530 Subject: [PATCH] Update maxN.md --- snippets/maxN.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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