Sha256: 6a2a34d0d2dc6b9cdf6a81576442276981d555746b0bf122b027a4527c291ce4

Contents?: true

Size: 340 Bytes

Versions: 2

Compression:

Stored size: 340 Bytes

Contents

module Huff
  class FrequencyMeter
    def initialize(text)
      @text = text
    end

    def frequency
      result = Hash.new { |h, k| h[k] = 0 }
      @text.each_char.
          each_with_object(result) { |char, hash| hash[char] += 1 }.
          map { |c, f| [f, c] }.
          sort { |(f1, _), (f2, _)| f1 <=> f2 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
huff-0.0.2 lib/huff/frequency_meter.rb
huff-0.0.1 lib/huff/frequency_meter.rb