From: botp Date: 2008-02-07T12:01:00+09:00 Subject: Re: Array Practice On Feb 7, 2008 7:20 AM, Adam Akhtar wrote: > As some of you may know from previous threads im trying to practice > specific areas of ruby. One simple exercise i set myself was taking a > elements in an array such as > > [1,2,3,1,2,2,4,3,2,1] > > and then grouping them together and putting them in subarrays within an > array like this > > [ [1,1,1], [2,2,2,2] , [3,3] ,[4] ] > irb(main):002:0> a=[1,2,3,1,2,2,4,3,2,1] => [1, 2, 3, 1, 2, 2, 4, 3, 2, 1] irb(main):003:0> a.group_by{|x|x} => {1=>[1, 1, 1], 2=>[2, 2, 2, 2], 3=>[3, 3], 4=>[4]} irb(main):004:0> a.group_by{|x|x}.values => [[1, 1, 1], [2, 2, 2, 2], [3, 3], [4]] ruby1.9 though. i'm threading on 1.9 since it is fast, i mean really fast, even on windows :) kind regards -botp