1let names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']
2
3let countedNames = names.reduce(function (allNames, name) {
4 if (name in allNames) {
5 allNames[name]++
6 }
7 else {
8 allNames[name] = 1
9 }
10 return allNames
11}, {})
12// countedNames is:
13// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
14