Deep flatten and housekeeping

Changed original flatten to be named deepFlatten, added normal flatten, improved some other snippets.
This commit is contained in:
Angelos Chalaris
2017-12-12 18:12:24 +02:00
parent 721e1f1d79
commit d44e228e14
5 changed files with 32 additions and 16 deletions

View File

@ -3,6 +3,6 @@
Use `reduce()` to increment a counter each time you encounter the specific value inside the array.
```js
const countOccurrences = (arr, value) => arr.reduce((a, v) => v===value ? a + 1 : a + 0, 0);
const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0);
// countOccurrences([1,1,2,1,2,3], 1) -> 3
```