Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Possible bug with array sort?

Author
Message
Kevin Cross
20
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 21st Mar 2018 23:10 Edited at: 21st Mar 2018 23:11
Not sure if this is a bug or intended but to me it doesn't seem right. If you sort an array with these two values: CKU and Chris it puts CKU before Chris. In order to get Chris before CKU I have to make the K and U in CKU as lowercase. I've found a solution for my project by making the whole value lowercase but thought I'd raise it as it doesn't seem right to sort casing.

And is it possible to get reverse sorting in a near future version please?
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Mar 2018 13:54 Edited at: 22nd Mar 2018 13:55
Hi Kevin

Please use MyArray.sort(1)

The "1" is important and will sort alphabetically instead of by ascii value.


As for reverse sorting, yes that would be good and hopefully they will add it but its not too hard to code your own reverse sort.



Obviously, this can be edited to sort type arrays instead of just string arrays.
Kevin Cross
20
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 22nd Mar 2018 14:12
Thanks Bengismo. I wasn't aware of putting 1 between the parenthesis. I did get it working just by converting each field to lower case but I'm guessing (1) will be much quicker.

And thanks for the example. I was just going to create another array containing the reversed data. I'll give your example a go later.
Kevin Cross
20
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 22nd Mar 2018 14:16
Just looked at the documentation to see if I can find information about .sort(1) and found that they have a reverse function so maybe I can just sort it alphabetically and then reverse it

Quote: "There are some additional array commands that don't fit in the above categories, they are .swap(index1,index2) to swap two elements in an array (including types and multidimenional arrays) and .reverse() to reverse the elements in an array."
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Mar 2018 14:23
Great!.. Well found!

Looks it was there all along.

Login to post a reply

Server time is: 2024-03-29 12:40:36
Your offset time is: 2024-03-29 12:40:36