I have this large array with dates in it. There is a function that sorts it
for me. The only problem is that in order for it to get sorted properly I
have to sort it AlphaNumericall y first using
this first:
list_b_array = cf_array.sort(f unction(a,b){re turn
compareAlpha(a[0],b[0]);});
then this:
list_array = list_b_array.so rt(function(a,b ){return
compareDate(a[0],b[0]);});
to get the values in list_array properly sorted. Anyone see anything wrong
with the compareDate() function?
The array is much larger. I've just shown how the date is formatted and that
null values exist.
var cf_array = [ "","11/10/2003","11/28/2004","" ];
function compareDate(a,b )
{
var date_a = new Date(a);
var date_b = new Date(b);
if (date_a < date_b) { return -1; }
else
{
if (date_a > date_b) { return 1; }
else
{ return 0; }
}
function compareAlpha(a, b)
{
//compare alpha charadcters
if ( a.toLowerCase() < b.toLowerCase() ) { return -1; }
if ( a.toLowerCase() > b.toLowerCase() ) { return 1; }
return 0;
}
for me. The only problem is that in order for it to get sorted properly I
have to sort it AlphaNumericall y first using
this first:
list_b_array = cf_array.sort(f unction(a,b){re turn
compareAlpha(a[0],b[0]);});
then this:
list_array = list_b_array.so rt(function(a,b ){return
compareDate(a[0],b[0]);});
to get the values in list_array properly sorted. Anyone see anything wrong
with the compareDate() function?
The array is much larger. I've just shown how the date is formatted and that
null values exist.
var cf_array = [ "","11/10/2003","11/28/2004","" ];
function compareDate(a,b )
{
var date_a = new Date(a);
var date_b = new Date(b);
if (date_a < date_b) { return -1; }
else
{
if (date_a > date_b) { return 1; }
else
{ return 0; }
}
function compareAlpha(a, b)
{
//compare alpha charadcters
if ( a.toLowerCase() < b.toLowerCase() ) { return -1; }
if ( a.toLowerCase() > b.toLowerCase() ) { return 1; }
return 0;
}
Comment