The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Reduce an array into a single object

Reduce an array into a single object

3:59
We'll look at using array.reduce to transform an array of strings into an object that counts the occurrence of each string in the array.
Watch this lesson now
Avatar
egghead.io

We'll look at using array.reduce to transform an array of strings into an object that counts the occurrence of each string in the array.

Avatar
Hussein Morsy

If you like, you can use a more compact implementation of the reducer:

var reducer = function(tally, vote) {
  tally[vote] = (tally[vote] || 0) + 1
  return tally;
}
In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?