Ruby Enumerable tally
03-Dec-2020 1406
For the Advent of Code, I was curious if there was a good way to do this in one line[1] (no technical reason, just because...)Not sure why, but it dawned on me this was likely something that Ruby would have built in (again, just because). It turns out in Ruby 2.7, the tally method was added to Enumerable.Tallies the collection, i.e., counts the occurrences of each element. Returns a hash with the elements of the collection as keys and the corresponding counts as values.
Ruby Enumerable tally #ruby #rubydeveloper #rubyonrails #Enumerable #tally https://rubyonrails.ba/link/ruby-enumerable-tally