Sha256: c63e5a248530bc69189eda3b72d49a15ed038978e2d5607380c42cca1ef214f1
Contents?: true
Size: 757 Bytes
Versions: 34
Compression:
Stored size: 757 Bytes
Contents
class Array def reduce(initial_value = 0, &proc) calculated_value = initial_value self.each_with_index do |e, i| calculated_value = yield(calculated_value, e, size, i) end calculated_value end def to_freq_hash freq = {} each do |e| freq[e] = freq[e].to_i + 1 end freq end def to_summarized_hash(operation_symbol = :+) sums = {} each do |e| key, value = yield(e) if sums[key] sums[key] = sums[key].send(operation_symbol, value) else sums[key] = value end end sums end def to_grouped_hash groups = {} each do |e| key, value = yield(e) groups[key] ||= [] groups[key] << value end groups end end
Version data entries
34 entries across 34 versions & 1 rubygems