Hacker News new | past | comments | ask | show | jobs | submit login

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.




Pretty 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.


True. I like Ruby's solution with exclamation marks, such as `sort!`, to make this kind of behaviour obvious.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: