From: Bertram Scharpf Date: 2009-10-01T21:40:14+09:00 Subject: Re: how do you do this Hi, Am Donnerstag, 01. Okt 2009, 21:23:30 +0900 schrieb George George: > 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"] x = %w(abc abcde def xyzwj) x.inject( Hash.new { |h,k| h[k] = [] }) { |h,e| h[e.length].push e ; h } Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de