cenze
02-15-2007, 05:50 PM
Hi Everyone,
I've been looking for a way to either ignore or control undefined elements in an array when sorting.
Either I'm overlooking something obvious, or this is really difficult! (most likely the former).
Just a quick picture in case I'm being ambiguous:
//array to be sorted
var array =
[
[A, 1],
[B, 2],
[, 3],
[D, 4],
[E,]
]
//desired outcome when sorting by a[0] b[0] comparison
A 1
B 2
D 4
E
3
//a successful sort on the numbers would leave them unchanged
In other words, I want undefined elements tossed on the bottom (or top depending on viewpoint) of a sort.
Is my terminology correct? Hopefully this makes sense.
Thanks a bunch!
--
Cenze
I've been looking for a way to either ignore or control undefined elements in an array when sorting.
Either I'm overlooking something obvious, or this is really difficult! (most likely the former).
Just a quick picture in case I'm being ambiguous:
//array to be sorted
var array =
[
[A, 1],
[B, 2],
[, 3],
[D, 4],
[E,]
]
//desired outcome when sorting by a[0] b[0] comparison
A 1
B 2
D 4
E
3
//a successful sort on the numbers would leave them unchanged
In other words, I want undefined elements tossed on the bottom (or top depending on viewpoint) of a sort.
Is my terminology correct? Hopefully this makes sense.
Thanks a bunch!
--
Cenze