Question: Why does
method, when called without parameters, sorts the elements of the array in alphabetical order (or lexicographical order). If some or all of the
elements are not strings, they are temporarily converted to strings, and then the array is alphabetically sorted. In the above example,
because that?s the correct alphabetical order of the strings '1', '10', '11', '2'.
If you need ascending number sorting, descending number sorting or, generally speaking, any sorting other than alphabetical, then you must supply your own sort order function (sometimes also called comparison function) as a parameter to
. The sort order function should take two arguments and return