Haha! I like this from that site: But due to the utter randomness of the comparison the black box goes mad, and how exactly it goes mad depends on the concrete implementation that differs between engines.
So yes, I think it's down to the JavaScript runtime itself where the problem lies.
Seasoned C++ developer with Physics, Maths, Medical Imaging background. Experience with PHP, Python, SQL (MariaDB, PostgreSQL). Into learning Vue/Quasar/supabase/TypeScript and sustainable tech.
Education
University of Tübingen and Potsdam, Max-Planck-Institute for Gravitational Physics
Well, the generic Array.sort() algorithm puts several requirements on the comparison function, see developer.mozilla.org/en-US/docs/W... which in turn it may use to implement the sorting algorithm. In the "Custom sort" approach above, in particular the requirement of the comparison to be "stable" is violated.
So, you are breaking the Array.sort() contract and may receive any result. In the worst case, the algorithm might not even terminate.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haha! I like this from that site:
But due to the utter randomness of the comparison the black box goes mad, and how exactly it goes mad depends on the concrete implementation that differs between engines.
So yes, I think it's down to the JavaScript runtime itself where the problem lies.
Well, the generic
Array.sort()
algorithm puts several requirements on the comparison function, see developer.mozilla.org/en-US/docs/W... which in turn it may use to implement the sorting algorithm. In the "Custom sort" approach above, in particular the requirement of the comparison to be "stable" is violated.So, you are breaking the
Array.sort()
contract and may receive any result. In the worst case, the algorithm might not even terminate.