# [Javascript] Sorting Problem

Tim Makins spindrift at oceanfree.net
Tue Sep 14 13:48:04 CDT 2004

```function numeric_sort(a, b) {
return (isNaN(a)&&isNaN(b))? alpha_sort(a,b): numSort(a,b);
}

function alpha_sort(a, b) {
if (a < b) {return -1}
else if (a > b) {return 1}
else {return 0}
}

function numSort(a,b){
return
(isNaN(parseFloat(a))?Number.POSITIVE_INFINITY:parseFloat(a)) -
(isNaN(parseFloat(b))?Number.NEGATIVE_INFINITY:parseFloat(b))
}

Sorry - I tried the above, and it still doesn't sort numerically.
Oh well, that's enough for today anyway - about time I stopped.

http://www.mapability.com/test/t3index.html

That's the page I'm working on. Only the 'States and Provinces' List is
there so far, and the map and help links don't work, as it is out of
context.

Tim in Ireland.

----- Original Message -----
From: "liorean" <liorean at gmail.com>
To: "[JavaScript List]" <javascript at latech.edu>
Sent: Tuesday, September 14, 2004 7:02 PM
Subject: Re: [Javascript] Sorting Problem

> On Tue, 14 Sep 2004 18:39:51 +0100, Tim Makins <spindrift at oceanfree.net>
wrote:
> > Well, that's a start. Its not crashing now, but the numerical search
results aren't quite right either
>
> Oh, I forgot. Most likely you'll want to parseFloat the a and b
> arguments in numSort.
>
> Second, I made a little mistake there:
>     (isNaN(b)?Number.POSITIVE_INFINITY:b)
> should be
>     (isNaN(b)?Number.NEGATIVE_INFINITY:parseFloat(b))
> --