String compressor (Ruby)
<p>Here is my code in ruby for a word compression.
For any given word (e.g. abbbcca) the compressed word/output should be in the format as "letter+repetition" (for above example, output: a1b3c2a1).</p>

<p>Here I'm so close to the completion but my result isn't in the expected format. It's counting the whole letters in <code>string.chars.each</code> thus resulting output as <code>a2b3c2a2</code>.</p>

<p>Any help?</p>

<pre><code>def string_compressor(string)
  new_string = []
  puts string.squeeze

  string.squeeze.chars.each { |s|
    count = 0

    string.chars.each { |w|
      if [s] == [w]
        count += 1
      end
    }

    new_string &lt;&lt; "#{s}#{count}"
    puts "#{new_string}"
  }

  if new_string.length &gt; string.length
    return string
  elsif new_string.length &lt; string.length
    return new_string
  else "Equal"
  end
end

string_compressor("abbbcca")
</code></pre>