Originally Posted by Airblader
Here's an example showing a difference. Consider this array and utility function (tested in Chrome):
The order is not the same but as you can check, both sort functions return a positive number for a.value > b.value. There's a number of ways to make them work the same, but the point is: The two decision functions discussed do not behave the same. The method that is able to return 0 is clearly the better one as it does not switch the elements that we think of as equal.
ok, but i explicitly said, twice, that there is no diff when sorting an array of unique strings
, like you might get from Object.keys(ob). you posted code sorting an array of objects
why do people who know the least usually know it the loudest?
a good faith effort, but not the scientific falsification of my hypothesis that we were all hoping for. If i said "all cars are red", and you wheel in a blue motorcycle, that doesn't really change the truthfulness of my statement... FULL DISCLOSURE: i don't expect that you will find a working example that contradicts my assertions about sorting unique Arrays. Maybe you can, it's a crazy world, but i would be pleasantly surprised.
afaik, the only way for a manual sort function to return zero is when the elements are the same. If you have an array of unique strings, that cannot happen. Therefore, that "return 0" branch is orphaned code in the context described.
of course, it's never to late to prove me wrong, i just wouldn't hold my breath on this one.