Created
August 1, 2019 14:29
-
-
Save IgorDePaula/3939f937fbdb30a1a577c90fbc7de519 to your computer and use it in GitHub Desktop.
reducer count names js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']; | |
var countedNames = names.reduce(function (allNames, name) { | |
if (name in allNames) { | |
allNames[name]++; | |
} | |
else { | |
allNames[name] = 1; | |
} | |
return allNames; | |
}, {}); | |
console.log(countedNames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment