AS3 Array.uniquesor: If the array has the same element, the sort is discarded

Source: Internet
Author: User
Tags array sort numeric sort

Today we have a strange AS3 array sort problem, and we know that Sorton can sort the elements of a group by a specified field. I do in the mail system, first according to the message status row, and then according to the index row

But the planning and I said there are bugs, I see there are really, all messed up. So I checked, found that the server is not wrong, should be sorton sort of wrong.

Test program:

The code is as follows Copy Code
1.var arr:array = [];
2.var Mailvo:object;
3.for (var i:int = 0;i < i++)
6.9
5. Mailvo = new Object ();
6. Mailvo.index = Index of i;//message, first sent index = 0
7. mailvo.state = 1;//message status, ==0 is unread, ==1 is read
8. Arr.push (Mailvo);
7.3
10.//I want unread messages to appear before
11.arr.sorton (["State"],[array.numeric]);
12.
13.for (i = 0;i < i++)
14.{
Trace (Arr[i].index);
16.}

Output results:

10 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18-19

I was thinking that if state is the same, the order should not change Ah!

Through group help, I knew the problem. The solution is:

Arr.sorton (["State"],[array.numeric | Array.uniquesort]);

Uniquesort: If the array has the same element, the sort is discarded

That's what the handbook says:

If any of the two elements or fields are to be sorted with the same value, the unique sort option terminates the sort.

And the sort of thing to note:

The element is sorted as a string regardless of the data type, so 100 is before 99, because the string value of "1" is less than the string value of "9".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.