From: Charles Snider Date: 2008-02-07T11:47:31+09:00 Subject: Re: Array Practice ------=_Part_23395_12291008.1202352440584 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline one line (36 chars) with uniq, map, and select On Feb 6, 2008 7:23 PM, Rob Biedenharn wrote: > 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 > > > > ------=_Part_23395_12291008.1202352440584--