4 ms·
Where is the issue comparing 1 and 11? 1 < 11 still returns true. [11,1].sort((a,b) => a -b) still returns [1, 11].
by xlm1717 11y ago
Where is the issue comparing 1 and 11? 1 < 11 still returns true. [11,1].sort((a,b) => a -b) still returns [1, 11].
- CJefferson 11y agoSorry, 1 and 11 isn't a problem in javascript. Insert two troublesome numbers :)
- evan_ 11y agoSeems like it should be up to you to come up with the troublesome numbers, since you're the one making claims.
- CJefferson 11y agoOh sorry, here we go. > [2] < [11] false Technically, a combination of integers and arrays. Still took me an afternoon to track down (it didn't occur to me javascript would work like that).
- gpvos 11y agoThen your knowledge of Javascript is sorely lacking. To make arrays work like that in Javascript would be very complicated, and counterintuitive to those who know how Javascript arrays work.
- CJefferson 11y agoI agree my knowledge of JavaScript is lacking, I just (wrongly) assumed arrays would act similarly to other languages. Obviously it's too late to change JavaScript now, but Iwould be interested to know why it would have been complicated to do this differently originally, and why it would be countintuitive? Is there anything I can read about this kind of thing?
- gpvos 11y agoYeah, that's more or less what you get when you hack a language together in 10 days... Arrays in JS are just a special case of objects, which are just name-value hashmaps. Although they usually have some optimizations in their internal implementation. I guess "Javascript: the Good Parts" is as good a place to start as any. It doesn't really go into the design decisions though.