z_mirza
06-06-2003, 06:26 AM
lets say i have an array of ten strings, now i want to sort them alphabetiacly, how will i do that?
|
Click to See Complete Forum and Search --> : sorting arrays z_mirza 06-06-2003, 06:26 AM lets say i have an array of ten strings, now i want to sort them alphabetiacly, how will i do that? brendandonhue 06-06-2003, 06:28 AM ArrayName.sort() z_mirza 06-06-2003, 06:30 AM wow are you seroios i didnt know there was a sort method, thanx alot brendandonhue 06-06-2003, 06:33 AM No prob. z_mirza 06-06-2003, 06:45 AM if all i had in those 10 strings were just 1 letter, how would i create my own sort()? Charles 06-06-2003, 06:46 AM See http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/array.html#1196882 for details concerning the use of the Array.sort() method. You can specify the sorting routine. z_mirza 06-06-2003, 07:19 AM well i want to write my own sort function that sorts an array of 10 strings or char how would i go about doing that i know the sort() is great but i would like to create my own yes a nonstandard sort is what i want basicly i want to know what is inside the sort() so i can prehaps build my own sort() thanx in adv z_mirza 06-06-2003, 07:36 AM ok i understand how to use the sort() and compare() but i would like to create my own sort() not use the one provided by javascript. in other words lets say a sort() doesnt exist, then how would i create one? z_mirza 06-06-2003, 07:44 AM there you go!!!! :D :D :D bubble sort! ive been trying to remember what it was called, yes i would like a bubble sort. thank you very much. if you could how how i would sort an array of strings with 1 letter and just explain to me how i an modify that sort to work with an array of strings with multiple letters sometimes starting with the same letters or almost the whole word i.e. Center Back Table Bold Statement Centers notice how the 1st and last element are very similar please explain how i would deal with that, but lets start small sense i am a newbie at this and sort an array of strings with just 1 letter. thanx alot dave edit: just wanted to ask on a side note, is bubble sort the way to go if im not using the built in sort()?? if not then could you show me the sort that is better jeffmott 06-06-2003, 08:49 AM is bubble sort the way to go if im not using the built in sort()??No. A bubble sort often taught in classes for its simplicity. But it is also one of the least efficient sort algorithms. Although I cannot say what algorithm the sort method implements, it is a very good bet that they would choose the best method currently known. So for productivity purposes there is no better alternative. For educational purposes, however, you may still learn about other sorting techniques (http://www.autoobjects.com/Home/Teaching/CmpE_126/CmpE_126_Lectures/Sortings/sortings.html).var ary = new Array("L","K","J","H","G","F","D","S","A","U"); eval("var sav = ['"+ary.join("','")+"']");I'll admit that I don't work in JavaScript nearly as much anymore, but after seeing this and doing a little reading I have to say I'm amazed that there is no clone method or something similar to copy an array without the use of an eval. But from the JavaScript 1.5 documentation the best method for creating a copy of an array appears to be, e.g.,var a = [1, 2, 3]; var b = eval(a.toSource());sadly, however, IE doesn't seem to support the toSource() method. z_mirza 06-06-2003, 11:54 AM well i got the bubble sort working for(i=0; i < arr.length; i++) for(j=0; j < arr.length-1; j++) if(arr[i].toLowerCase() < arr[j].toLowerCase()) { var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } but sense most people frown upon bubble sort ill see what else i can do and Dave i would like to hear what you have to say when you get time. thanx guys z_mirza 06-06-2003, 07:02 PM ehh kinda confusing but i think i got it, thanx alot dave z_mirza 06-06-2003, 07:11 PM oh yea i figured that out after playing around with the sorts. thanx again Grumelo 02-12-2009, 10:59 AM See http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/array.html#1196882 for details concerning the use of the Array.sort() method. You can specify the sorting routine. Unfortunately this link is not working anymore, but the explanations on my blog (http://www.grumelo.com/2009/02/12/sorting-multi-dimensional-javascript-arrays/) are still available :D Mayday 02-12-2009, 12:16 PM Why do you keep reviving long-buried archived threads on the same subject? :confused: (this is at least the 3rd such OLD thread you've posted your blog link on, and previously to your necromancy, was last posted on in 2003! :eek: Grumelo 02-12-2009, 01:02 PM Come on, the thread is maybe old but the subject is still alive. Many people are still searching for answers and Webdevelopper.com is in the top of the answers provided by Google. What a shame to find the right thread without the right answer. Mayday 02-12-2009, 01:53 PM So, post 1 brand spanking new thread if it's that important to you. It's unnecessarily repetative to post the same thing on several threads, and even moreso on ones that haven't been active for months, or even years like this one. Grumelo 02-12-2009, 02:13 PM Ok, sorry Next time I will create a new post. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |