This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pass in an enumeration of data and | |
# (optionally) a block to extract the grouping aspect of the data. | |
# | |
# Optional: sort_by lambda (operates on group key and count) | |
def puts_hist(data, sort_by: nil, &block) | |
data = data.map(&block) if block | |
counts = data.each_with_object(Hash.new(0)) { |k, h| h[k] += 1 } | |
max = counts.values.max | |
width = ENV['COLUMNS'].to_i |