tailieunhanh - JavaScript Bible, Gold Edition part 214

JavaScript Bible, Gold Edition part 214. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | CD-622 Part VI Appendixes Listing 37-8 continued Enter a string to act as a delimiter between entries INPUT TYPE text NAME delim VALUE SIZE 5 P INPUT TYPE button VALUE Array as-is onClick showAsIs INPUT TYPE button VALUE Reverse the array onClick reverseIt INPUT TYPE reset INPUT TYPE button VALUE Reload onClick TEXTAREA NAME output ROWS 4 C0LS 60 TEXTAREA F0RM BODY HTML Notice that the method stands by itself meaning nothing captures the returned value because the method modifies the solarSys array. You then run the now inverted solarSys array through the method for your text display. array .sort compareFunction NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 Compatibility Example You can look to Listing 37-9 for a few examples of sorting an array of string values. Four buttons summon different sorting routines three of which invoke comparison functions. This listing sorts the planet array alphabetically forward and backward by the last character of the planet name and also by the length of the planet name. Each comparison function demonstrates different ways of comparing data sent during a sort. Listing 37-9 Possibilities HTML HEAD TITLE TITLE SCRIPT LANGUAGE solarSys new Array 9 Appendix F Examples from Parts III and IV CD-623 solarSys 0 Mercury solarSys 1 Venus solarSys 2 Earth solarSys 3 Mars solarSys 4 Jupiter solarSys 5 Saturn solarSys 6 Uranus solarSys 7 Neptune solarSys 8 Pluto comparison functions function compare1 a b reverse alphabetical order if a b return -1 if b a return 1 return 0 function compare2 a b last character of planet names var aComp - 1 var bComp - 1 if aComp bComp return -1 if aComp bComp return 1 return 0 function compare3 a b length of planet names return - sort and display array function sortIt form compFunc var delimiter if compFunc null else .

TỪ KHÓA LIÊN QUAN