This is a perfect opportunity to use Array#reduce
. That function will take a function that is applied to all elements of the array in order and can be used to accumulate a value. We can use it to accumulate an object with the various counts in it.
To make…
Top comments (0)