> Take a look at this: > > # use a hash whose values default to 0 for proper data structure use > # use count as the name, since that's what it is storing. > count = Hash.new 0 > > # iterate over each string only once > strings.each do |string| > # increment the count for each string > count[string] += 1 > end > > p count > > If you nuke all the comments, the code makes just as much sense (if > not more). That's what we try to achieve in ruby whenever we can. Hi Ryan, Don't know if you'll be reading this, but wanted to say thanks anyway. After reading the section you suggest from Pickaxe I came up with this, which is not perfect, but definitely an improvement: array = ["a", "b", "a", "b", "b"] count =[] for i in 0 ... array.uniq.length temp_count = 0 array.collect{|elem| temp_count +=1 if elem == array.uniq[i]} count << temp_count end p array.uniq, count Then I worked through your code and realized what a concise solution you had proposed. I have changed my programme accordingly and it is now considerably shorter and easier to read. Thanks again and thanks to everyone else who made suggestions too. -- Posted via http://www.ruby-forum.com/.