Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi:
 
  i come from china. If my English is not good,  hope you can understand. i am using Google  translation 
  I was confused about the example on chapter 7.2.2. About function sort(). The book says:

var numbers = [1, 4, 3, 2];
numbers.sort(); //4, 1, 3, 2

why it ordered  4, 1, 3, 2? I test this code and it always to be 1, 2 ,3 ,4  .even IE 6.

 

thank you.

Share this post


Link to post
Share on other sites

Sorting appears to be a problem with early browsers but with use of function x-y problem has been resolved with modern browsers. Click on link for more detailed info on numbers.sort()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2Fsort

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...