Hey Cats, I''m having a problem. I''m working with an object that contains a bunch of arrays: var myObject = { "data": [ {"line": [1,"aoo","far"]}, {"line": [2,"boo","ear"]}, {"line": [3,"coo","dar"]}, {"line": [4,"doo","car"]}, {"line": [5,"eoo","bar"]}, {"line": [6,"foo","aar"]} ] }; I''d like to be able to sort across the arrays. so that the objects in the "data" array rearange themselves based on what column of the "line" arrays are sorted. So for instance if I wanted to sort on myObject.data.line[2] the object would rearrange itself to look like: var myObject = { "data": [ {"line": [6,"foo","aar"]}, {"line": [5,"eoo","bar"]}, {"line": [4,"doo","car"]}, {"line": [3,"coo","dar"]}, {"line": [2,"boo","ear"]}, {"line": [1,"aoo","far"]} ] }; It seems like I should be able to use the collect method in prototype to achieve this, but I can''t quite wrap my head around how. :) If anyone has any advice that would be great. Thanks in advance. - J
On 2/17/06, Jason Hummel <jhummel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So for instance if I wanted to sort on > myObject.data.line[2] the object would rearrange itself to look like:Thant would be myObject.data = myObject.data.sortBy( function(v){ return v.line[2] }); Bye, Martin
All I gotta say is... Wow. That''s amazing. One line? I was way off. Thanks for the help. I''ll be looking into that interesting little method a lot more. On 2/18/06, Martin Bialasinski <klingeling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/17/06, Jason Hummel <jhummel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > So for instance if I wanted to sort on > > myObject.data.line[2] the object would rearrange itself to look like: > > Thant would be > myObject.data = myObject.data.sortBy( function(v){ return v.line[2] }); > > Bye, > Martin > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >