Fully renamed and updated everything, tagged, built
This commit is contained in:
10
snippets/countOccurrences.md
Normal file
10
snippets/countOccurrences.md
Normal file
@ -0,0 +1,10 @@
|
||||
### countOccurrences
|
||||
|
||||
Counts the occurences of a value in an array.
|
||||
|
||||
Use `Array.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);
|
||||
// countOccurrences([1,1,2,1,2,3], 1) -> 3
|
||||
```
|
||||
Reference in New Issue
Block a user