mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-21 19:45:16 +08:00

The [built-in JavaScript sort method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) will perform a lexicographical (aka alphabetical) order by converting the elements of the array to strings. This can yield unexpected results when sorting numbers. A comparison function can be passed into the sort method to indicate how array elements should be compared.