From: Ryan Davis Date: 2010-03-23T19:04:06+09:00 Subject: Re: sort elements On Mar 23, 2010, at 02:47 , Juan Gf wrote: > a = 'Apple car caR house tree ice ice ice house' > b = a.downcase.split(' ') > b.uniq.each do |element| > puts "#{b.count(element)}\t#{element}" > end > > > But this code produces this: > > 1 apple > 2 car > 2 house > 1 tree > 3 ice > > > and I want something like this: > > 3 ice > 2 car > 2 house > 1 apple > 1 tree > > Any ideas? Read aloud what the code says, translated to natural language (English or otherwise, doesn't matter... just raise it to human thought level). Then say aloud what you want it to do, step by step. What's the difference? Translate that difference back down to code.