Open Bug 1343142 Opened 3 years ago Updated 16 days ago

Clarify that Array.prototype.sort() sorts in increasing order

Categories

(Developer Documentation :: JavaScript, defect, P5)

All
Other
defect

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: jan, Unassigned)

References

()

Details

:: Developer Documentation Request

      Request Type: Correction
     Gecko Version: unspecified
 Technical Contact: 

:: Details

Yes, if 'apples' comes before 'bananas' we deduce that it's sorted in increasing order, but it should be stated upfront, e.g.:

"The sort() method sorts the elements of an array in place and returns the array sorted in increasing order."

It would be really nice to have an example how to sort in decreasing order, e.g.:

function compareForDecsendingOrder(a, b) {
  if (a < b) return 1 else return -1;
}

Hi Jan, I have edited the docs to point out that the default sorting order is ascending. I think the rest has already been taken care of.

You need to log in before you can comment on or make changes to this bug.