Let’s step into the code part.
Sort method order the value as string, it’s work fine for string but if its number. sorting it will return incorrect data for the numbers. To overcome this issue we need to use compare function.
Compare function return less than 0, sort `a` to an index lower than `b` then `a` comes first. If Compare function returns 0 it will be unchanged but sort the other element. if Compare function is greater than 0, it will sort `b` to an index lower than `a`, `b` comes first.
Please let me know your feedback and suggestion.