Explanation:
According to documentation the syntax is arr.sort([compareFunction]) and compareFunction - is an optional paramter, if ommited the array is sorted according to each character's Unicode code point value, according to the string conversion of each element.
To correctly sort an array of ints valid compareFunction must be provided:
> [0,1,2,3,4,5,6,7,8,9,10].sort((a,b) => a - b)
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
I am curious if the default behaviour of
array.sort
method worth a WTF?Explanation: According to documentation the syntax is
arr.sort([compareFunction])
andcompareFunction
- is an optional paramter, if ommited the array is sorted according to each character's Unicode code point value, according to the string conversion of each element.To correctly sort an array of ints valid
compareFunction
must be provided: