3 ms·
new Int32Array([2,7,-2, -7]).sort() Result: Int32Array [-7, -2, 2, 7] (4) The problem is you can put anything in array and JS can't really check that "everyth
by leshenka 2y ago
new Int32Array([2,7,-2, -7]).sort()
Result: Int32Array [-7, -2, 2, 7] (4)
The problem is you can put anything in array and JS can't really check that "everything here is a number", so it uses string as a common type because everything can be converted to string.
we need proper typed arrays, like Int8/16/32Array but with any class, not just int. The class itself will then define how to compare instances (python's __gt__ and so on).