|
Post by docclox on Aug 15, 2010 1:18:15 GMT -5
Daisy, following on from the blog (blogger hates me) the reason you're sorting algorithm thinks 2 > 10 is most likely that you're indexing the array with strings.
In that case, it'll try and sort (what it assumes are) the words into dictionary order, in which case 2 > 10 would be correct.
It's probably worthwhile making sure that your subscripts are explicitly coerced to ints if you're using arrays as arrays. Otherwise you can get all sorts of conversion errors down the line.
(and apologies if I'm teaching granny to suck eggs with this one)
|
|
|
Post by daisy_strike on Aug 15, 2010 8:38:16 GMT -5
You are correct sir, the thing that pissed me off was that they were an array of integers and the native sort still sorted them as a string... The documentation on it was very helpful. and i quote from help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#sort()"...you can create your own custom function to do the sorting." was what pissed me off to high heaven. Which is exactly what i did. Though in the stupidist way possible... i chopped everything that was 10 and over and put them in another array. Then combined them back together afterwards. Daisy
|
|
|
Post by docclox on Aug 15, 2010 11:13:46 GMT -5
I didn't know it would do that. I guess the native sort must coerce the array contents to strings before sorting. Makes sense I suppose if you want to be able to sort arbitrary data types.
Don't blame you in the least for getting annoyed at it, though.
|
|