From: Paul Smith Date: 2009-10-01T21:35:50+09:00 Subject: Re: how do you do this On Thu, Oct 1, 2009 at 1:23 PM, George George wrote: > Given an array of strings e.g. >  x = ["abc","abcde" "def","xyzwj"] and of different lengths, > how can you efficiently create new arrays of strings which are of the > same length. for example the above array can be transformed into Well, here's something close: h = {} x.each do |i| h[i.length] ||= [] h[i.length] << i end h is now a hash: {3=>["abc", "def"], 5=>["abcde", "xyzwj"]} That's close enough to what you want that I'm sure you can run with it. Look in the "Group by unique entries of a hash" thread for more ideas. > > x1 = ["abc","def"] > x2 = ["abcde","xyzwj"] > > Thank you. > -- > Posted via http://www.ruby-forum.com/. > > -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk