arr.sort() shunts the wagons of train #1 itself: what does it compare when it gets no comparator? With one, every comparison the engine made is logged and…
The key idea
With no comparator sort orders text; a comparator gives a number
Try it in this playground
Sort numbers with no comparator See every value become text first, then 100 land before 2.
Use (a, b) => a - b Follow every comparison: negative means a first.
Sort words by length Words of the same length keep the order they came in.
Try a true/false comparator (a, b) => a > b never gives a negative number.