From bf5304e5513c70f4e259649fe0ac88f9483a0ab7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 24 Apr 2020 10:47:05 +0300 Subject: [PATCH] Update uniqueElements.md --- snippets/uniqueElements.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/uniqueElements.md b/snippets/uniqueElements.md index 2cf6ebb1d..fe065e1fe 100644 --- a/snippets/uniqueElements.md +++ b/snippets/uniqueElements.md @@ -3,9 +3,9 @@ title: uniqueElements tags: array,beginner --- -Returns all unique values of an array. +Returns all unique values in an array. -Use ES6 `Set` and the `...rest` operator to discard all duplicated values. +Create a `Set` from the given array to discard duplicated values, then use the spread operator (`...`) to convert it back to an array. ```js const uniqueElements = arr => [...new Set(arr)]; @@ -13,4 +13,4 @@ const uniqueElements = arr => [...new Set(arr)]; ```js uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5] -``` \ No newline at end of file +```