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();
}
//the following sorts a record set with a Date object as a property of each
record, or, in other words, an array of objects with a Date object property:
function sortDate(a:Array, j:String, k: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][j][b[f]](),a[g][j][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(k)a.reverse();
}
The k variable is omitable, it determines whether to reverse the dates after
they've been descendingly sorted.
I sort of copt out towards the end with the reverse function, I should have
built the ascending option into the algorithm for tighter optimization.
Please feel free to mangle,
H
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders