rename distinctValuesOfArray into uniqueElements
This commit is contained in:
@ -1,13 +0,0 @@
|
|||||||
### distinctValuesOfArray
|
|
||||||
|
|
||||||
Returns all the distinct values of an array.
|
|
||||||
|
|
||||||
Use ES6 `Set` and the `...rest` operator to discard all duplicated values.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const distinctValuesOfArray = arr => [...new Set(arr)];
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
distinctValuesOfArray([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
|
||||||
```
|
|
||||||
13
snippets/uniqueElements.md
Normal file
13
snippets/uniqueElements.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
### uniqueElements
|
||||||
|
|
||||||
|
Returns all unique values of an array.
|
||||||
|
|
||||||
|
Use ES6 `Set` and the `...rest` operator to discard all duplicated values.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const uniqueElements = arr => [...new Set(arr)];
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user