Deep flatten and housekeeping
Changed original flatten to be named deepFlatten, added normal flatten, improved some other snippets.
This commit is contained in:
@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user