Hi zwetan,
The valueOf method is key, I would probably have to say that I had alot of
fun writing my solution, but your solution makes much more sense. I
appreciate your response :)
H
On 1/10/06, zwetan <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> >
> > I wrote a portable date sorting algorithm, I thought it might be of
> > interest
> > to my peers since I've only seen date sorting implementations for data
> > grids.
> >
> > //the following sorts an array of Date objects:
> >
> > function sortDateArray(a:Array, j:Boolean) {
> > var
> > b=['getYear','getMonth','getDate','getTime'],c=a.length,d=b.length,e
> > = -1,f,g,h,i;
> > while(++e<c){
> > i = c-e-1;
> > for(g=-1;++g<c-e;)
> > for(f=-1;++f<d;){
> > h=[a[i][b[f]](),a[g][b[f]]()];
> > if(h[0]!=h[1])
> > if(h[0]<h[1]) i = g;
> > else break;
> > else continue;
> > }
> > a.push(a.splice(i, 1)[0]);
> > }
> > if(j)a.reverse();
> > }
> >
> [snip]
> > Please feel free to mangle,
> >
>
> Without wanting to mangle too much
> But the language already provide a sort function for arrays
> that you could reuse
>
> also the valueOf() method of the Date object could
> simplify a lot the comparison of values
>
> list = [ new Date( 1901, 1, 1), new Date(), new Date(2003,1,5), new
> Date(2005,3,5) ];
>
> function sortDateArray2( a, b )
> {
> a = a.valueOf();
> b = b.valueOf();
>
> if( a > b )
> {
> return 1;
> }
> else if( a == b )
> {
> return 0
> }
>
> return -1;
> }
>
>
> list.sort( sortDateArray2 );
> trace( list.join( "\n" ) );
>
> ----
> Fri Feb 1 00:00:00 UTC+0100 1901
> Wed Feb 5 00:00:00 UTC+0100 2003
> Tue Apr 5 00:00:00 UTC+0200 2005
> Wed Jan 11 03:07:31 UTC+0100 2006
> ----
>
> zwetan
>
>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders