JavaScript Bug When Using Array.sort() on Numeric String Formats
I’ll introduce the bug that occurs when using Array.sort() on numeric string formats in JavaScript.
['99','100','101'].sort()
// [ '100', '101', '99' ]
['99','100','101'].sort((a, b) => parseFloat(a) - parseFloat(b));
// [ '99', '100', '101' ]
[99,100,101].sort((a, b) => a - b);
// [ 99, 100, 101 ]
That’s all from the Gemba.