dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: Pathetic Javascript language can't sort an array!

  1. #1
    Join Date
    Feb 2008
    Posts
    11

    Pathetic Javascript language can't sort an array!

    <script defer>



    arr=new Array()
    arr[0]='45'
    arr[1]='223'
    arr[2]='672'
    arr[3]='664'
    arr[4]='23'
    arr[5]='!b'
    arr[6]='@b'
    arr[7]='mansion'

    arr.sort()
    alert(arr)
    </script>

    returns !b,223,23,45,664,672,@b,mansion while it is supposed to return
    !b,@b,23,45,223,664,672,mansion . This is the 100000000000000 bug in this piece of **** language.

  2. #2
    Join Date
    Mar 2011
    Posts
    1,156
    The ASCII value of '@' is 64, which is the highest value for the first characters in all of the elements in your array and why JavaScript puts it last.

  3. #3
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131

  4. #4
    Join Date
    Dec 2010
    Posts
    59
    The moral of the story here is think before you post.

  5. #5
    Join Date
    Feb 2008
    Posts
    11
    Quote Originally Posted by rtrethewey View Post
    The ASCII value of '@' is 64, which is the highest value for the first characters in all of the elements in your array and why JavaScript puts it last.
    I need to sort values like system sorts files, not some non standard ASC|| bull****. If I create files and sort them by name, '@' file will stand before any numerically named file. Check the picture. http://img191.imageshack.us/img191/6131/sortl.jpg @b file stands before 23.
    Quote Originally Posted by JunkMale View Post
    This would not help even if I wanted to sort in ASC|| way. I get Number Expected error (Line 171) and it does not sort. Pathetic.

    Quote Originally Posted by ralphchadkirk View Post
    The moral of the story here is think before you post.
    Provide the solution first kid.

  6. #6
    Join Date
    Aug 2007
    Posts
    3,767
    If you don't like the default sorting function in JavaScript as defined in the standard, provide your own sorting function. That's why sort accepts a function! And as you seem to be unaware or uninterested, Windows does not have one consistent sorting order, in fact, it has an apparantly "intuitive sort" occasionaly. And why would you expect someone to help you when you constantly complain about the language? It's difficult enough to use a language that has multiple definitions on multiple platforms without complaining about what is implemented correctly!

    BTW, you haven't even discovered all the "bugs" yet!
    Last edited by Declan1991; 10-22-2011 at 02:46 PM.

  7. #7
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Quote Originally Posted by select View Post
    This would not help even if I wanted to sort in ASC|| way. I get Number Expected error (Line 171) and it does not sort. Pathetic.
    You obviously didn't read the tutorial.

  8. #8
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    You can always build your own sorting function; there are several popular methods. I tend to use two arrays and loop through (the first) to find the max or min (adding it to the second) until all entires have moved from one (the first) to another (the second).

  9. #9
    Join Date
    Nov 2010
    Posts
    1,097
    Quote Originally Posted by select
    This would not help even if I wanted to sort in ASC|| way. I get Number Expected error (Line 171) and it does not sort. Pathetic.
    look at the example given at the end of the tutorial. It returns:

    !b 23 45 223 664 672 @b mansion

    for numeric sorting, which seems to be pretty close to what you want. I guess you will have to code some sort of exception for @

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles