Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Last active September 30, 2016 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dammmien/66e23b68180cb87f6a17 to your computer and use it in GitHub Desktop.
Save Dammmien/66e23b68180cb87f6a17 to your computer and use it in GitHub Desktop.
Counting the occurrences of elements in an array.
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