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

Introducing Reduce: Reducing an Array into an Object

Introducing Reduce: Reducing an Array into an 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?