[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sorting object by date

Thai Le

2/7/2007 3:55:00 AM

Hey guys,
I need a fast way to sort an array of object by their .time in xml time
scheme. In java,it would be easy using priority queue,is there any thing
similar to priority queue in ruby? Since this is a very small app, it
would be waste of time trying to implement a priority queue.
Thai

--
Posted via http://www.ruby-....

4 Answers

Jano Svitok

2/7/2007 10:33:00 PM

0

On 2/7/07, Thai Le <lnthai2002@yahoo.com> wrote:
> Hey guys,
> I need a fast way to sort an array of object by their .time in xml time
> scheme. In java,it would be easy using priority queue,is there any thing
> similar to priority queue in ruby? Since this is a very small app, it
> would be waste of time trying to implement a priority queue.
> Thai

In ruby, you can sort array either by using Array#sort, or Array#sort_by.
Provided that your .time values have proper <=> operator, you can do:

sorted_array = array_of_objects.sort_by {|o| o.time}

If the <=> operator is not available, you can replace o.time above
with e.g. conversion to timestamp, or implement your own:

sorted_array = array_of_objects.sort {|a,b| ...put here the comparison...}

(the sort by version is faster, as it makes the conversion only once
per array item.

For more details see documentation
(http://ruby-doc.org/core/classes/Array.ht...)

The Revd

1/15/2013 1:52:00 PM

0

On Tue, 15 Jan 2013 05:38:02 -0800 (PST), Grikboxer?? The Grik piece
of skata <kickboxer861@gmail.com> wrote:

>> Whatever it is, may it penetrate your rectum, insh'Allah.
>
>Feelings of revenge galore.

We're not interested in your 'feelings', you Grik piece of skata.

KickBoxer GR

1/15/2013 2:21:00 PM

0

> We're not interested in your 'feelings', you Grik piece of skata.

Those are your feelings you degenerate swine and child rapist.

The Revd

1/15/2013 2:38:00 PM

0

On Tue, 15 Jan 2013 06:20:41 -0800 (PST), Grikboxer?? The Grik piece
of skata <kickboxer861@gmail.com> wrote:

>> We're not interested in your 'feelings', you Grik piece of skata.
>
>Those are your feelings you degenerate swine and child rapist.

No, those are YOUR feelings, you feeble-minded Grik piece of skata.
Greek you!