Build README

This commit is contained in:
Angelos Chalaris
2017-12-12 12:12:44 +02:00
parent b3dbb0e233
commit 03bfaf6b7a
2 changed files with 3 additions and 9 deletions

View File

@ -83,10 +83,10 @@ var capitalize = str => str.slice(0, 1).toUpperCase() + str.slice(1);
### Count occurrences of a value in array
Use `filter()` to create an array containing only the items with the specified value, count them using `length`.
Use `reduce()` to increment a counter each time you encounter the specific value inside the array.
```js
var countOccurrences = (arr, value) => arr.filter(v => v === value).length;
var countOccurrences = (arr, value) => arr.reduce((a, v) => v===value ? a + 1 : a + 0, 0);
```
### Current URL

View File

@ -1,12 +1,6 @@
### Count occurrences of a value in array
Use `filter()` to create an array containing only the items with the specified value, count them using `length`.
```js
var countOccurrences = (arr, value) => arr.filter(v => v === value).length;
```
Use reduce() to increment a counter each time you encounter the specific value; does not create new array like filter().
Use `reduce()` to increment a counter each time you encounter the specific value inside the array.
```js
var countOccurrences = (arr, value) => arr.reduce((a, v) => v===value ? a + 1 : a + 0, 0);