Created
September 1, 2015 14:58
-
-
Save aclave1/a68fdf84e27c031231f2 to your computer and use it in GitHub Desktop.
count the number of times an element occurs 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
[1,2,3,1,1,2,3,4].reduce(function(map,val){ | |
map[val] = typeof map[val] !== 'undefined' ? map[val]+1 : 1; | |
return map; | |
},{}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment