It is an inplace sort for an array and sorted array would be some thing like this
However, if numbers are sorted as strings, “25” is bigger than “100”, because “2” is bigger than “1”. Because of this, the sort() method will produce an incorrect result when sorting numbers. You can fix this by providing a “compare function”
Compare function will look some thing like this
When the sort() method compares two values, it sends the values to the compare function, and sorts the values according to the returned (negative, zero, positive) value.
So final number array example looks something like this.