From: Paul Smith Date: 2009-10-01T21:38:20+09:00 Subject: Re: how do you do this On Thu, Oct 1, 2009 at 1:34 PM, Ilan Berci wrote: > 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 >> >> x1 = ["abc","def"] >> x2 = ["abcde","xyzwj"] >> >> Thank you. > > y = {} > x.each do |v| >  y[v.length] || = [] >  y[v.length] << v > end > y.values > LOL :) I love Ruby and Rubytalk :) > or if you prefer less lines.. > > x.inject({}) do |h, v| >  (y[v.length] || = []) << v >  h > end.values Must.... master..... inject..... -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk