4 ms·
Yes yes, everyone one is saying "of course" these are string compares! What a nub mistake. But is it? It is a very easy mistake to make, you pick 'sort' and t
by wscott 11y ago
Yes yes, everyone one is saying "of course" these are string compares! What a nub mistake. But is it?
It is a very easy mistake to make, you pick 'sort' and the resulting code does what you expect. As long as all the timet's have the same number of digits then the string comparison works. You have to have a data that crosses 9/8/2001 to see the problem. (or 3/3/1973 before that)
The javascript compiler isn't going to tell you about this and it only hits a problem with dates older than most programs that are written in javascript.
- oldmanjay 11y agoThis behavior has been documented forever, and the broken code written in ignorance of this behavior passed into production because of inadequate testing. Nothing you've said countered these facts.
- fenomas 11y agoCertainly it's an easy mistake to make, but most JS devs tend to encounter it the very first time they call sort() on anything that isn't epoch dates. The fact that the author's code worked for years is a pretty exotic edge case!
- deleted 11y ago[deleted]