prefixed Array. to reduce(), sort(), map() methods in snippets.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
### Count occurrences of a value in array
|
||||
|
||||
Use `reduce()` to increment a counter each time you encounter the specific value inside the 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);
|
||||
|
||||
Reference in New Issue
Block a user