Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.23 KB | None | 0 0
  1. var arr = ['a','b','c','d','d','e','a','b','c','f','g','h','h','h','e','a'];
  2. return arr.reduce(function(acc, cur) {
  3. acc[cur] = (acc[cur] || 0) + 1;
  4. return acc;
  5. },{});
  6. // prints { a: 3, b: 2, c: 2, d: 2, e: 2, f: 1, g: 1, h: 3 }
Add Comment
Please, Sign In to add comment