4 ms·
The comma is not material here: the answer is the same if we write `const x = ...; const y = ...`. And that's the first gotcha: sort() is in place.
by gmac 5y ago
The comma is not material here: the answer is the same if we write `const x = ...; const y = ...`.
And that's the first gotcha: sort() is in place.
- dahart 5y agoPretty sure I’ve actually tripped on sort() myself before by assuming it was a new array. It does make sense for performance though, creating a new array would be a bad default choice for performance, for the same reasons that forEach is generally faster than map all else being equal.
- gmac 5y agoTrue. I like Ruby's solution with exclamation marks, such as `sort!`, to make this kind of behaviour obvious.