Last active
September 30, 2016 09:09
-
-
Save Dammmien/66e23b68180cb87f6a17 to your computer and use it in GitHub Desktop.
Counting the occurrences of elements in an array.
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 arr = "The quick brown fox jumps over the lazy dog".split( '' ); | |
arr.reduce( ( countMap, item ) => { | |
countMap[ item ] = ( countMap[ item ] || 0 ) + 1; | |
return countMap; | |
}, {} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment