Update countOccurrences function
Removes unnecessary addition of `0`.
This commit is contained in:
@ -5,7 +5,7 @@ Counts the occurrences of a value in an array.
|
|||||||
Use `Array.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
|
```js
|
||||||
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
|
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user