Javascript implementation code for a special sorting requirement _ javascript skills

Source: Internet
Author: User
After reading it, 1 is a hand itch, 2 is to think there is a problem with the implementation of the landlord, just write it, with js, it took about 30-40 minutes. Original question post here: http://topic.csdn.net/u/20081130/09/18d455a6-65e1-4d00-aa8c-d9742654cd8c.html

Before sorting: "Zo", "Ad", "bC", "dad", "bood", "bada", "Admin", "Good", "aete ", "cc", "Ko", "Beta", "cocould", "AAA" <script type = "text/javascript"> var t = ["Zo ", "Ad", "bC", "dad", "bood", "bada", "Admin", "Good", "aete", "cc", "Ko ", "Beta", "cocould", "AAA"]; // var t = ['aaa', 'aaa']; function sort (arr) {for (var I = 0; i0) {var tmp = arr [j]; arr [j] = arr [j + 1]; arr [j + 1] = tmp ;}}} function compare (str1, str2) {/** if (str1> str2) {re Turn 1;} return 0; **/var r = 0; for (var I = 0, j = 0; I <str1.length & j <str2.length; I ++, j ++) {status = 'I =' + I + 'J = '+ j; var c1 = str1.charCodeAt (I); var c2 = str2.charCodeAt (j ); if (c1> = 97) c1-= 32; if (c2> = 97) c2-= 32; if (c1> c2) {return 1 ;} else if (c1 <c2) {return 0;} else if (c1 = c2) {if (str1.charCodeAt (I)> str2.charCodeAt (j) {return 1 ;} else if (str1.charCodeAt (I) <str2.charCodeAt (j) {return 0 ;} Else if (str1.charCodeAt (I) = str2.charCodeAt (j) {continue ;}} if (I! = Str1.length) {return 1;} else if (j! = Str2.length) {return 0 ;}} sort (t); alert ("sorted:" + t); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.