From: Rob Biedenharn Date: 2008-02-07T11:23:17+09:00 Subject: Re: Array Practice On Feb 6, 2008, at 8:30 PM, Clifford Heath wrote: > Curt Sampson wrote: >> On 2008-02-07 08:20 +0900 (Thu), Adam Akhtar wrote: >>> [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] ] >> The Array#assoc method is your friend here. > > Really? Where's the array containing arrays come from? > > ------------------------------------------------------------ > Array#assoc > array.assoc(obj) -> an_array or nil > ------------------------------------------------------------------------ > Searches through an array whose elements are also arrays > comparing obj with the first element of each contained array > using obj.==. Returns the first contained array that matches > (that is, the first associated array), or nil if no match is > found. See also Array#rassoc. > > Clifford Heath. Array#assoc searches an existing array of arrays; it doesn't build one. [ [1,1,1], [2,2,2,2] , [3,3] ,[4] ].assoc(2) => [2,2,2,2] [ [1,1,1], [2,2,2,2] , [3,3] ,[4] ].assoc(5) => nil -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com