Additional snippets

This commit is contained in:
Angelos Chalaris
2017-11-30 19:12:13 +02:00
parent 292aad75bc
commit bb40a7ec08
9 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,13 @@
### Unique values of array
Use `reduce()` to accumulate all unique values in an array.
Check if each value has already been added, using `indexOf()` on the accumulator array.
```js
var uniqueValues = arr =>
arr.reduce( (acc, val) => {
if(acc.indexOf(val) === -1)
acc.push(val);
return acc;
}, []);
```