Sort arrays with sort

Sort arrays with sort
0

#1

Hello everyone,

I don’t get it why when I comment array.sort(); it does work but when I uncomment it, it doesn’t work anymore.

A little explanation please


#2

Do you mean when you uncomment the //array.sort() at the end? (In the future, it’s much easier to read and debug your code if you share it as formatted text or a repl.it embed rather than a screenshot.)
If that’s what you’re talking about, then the problem is that if you do a array.sort() at the end, you’re undoing the array.sort(a,b)... that you did above. You’re essentially saying “Sort the array using this rule. Now sort that array using the default sort rule.” The default .sort() is a lexical (alphabetic) sort that will put 11 before 2.