I'm a Senior DevOps Architect and publish most of my projects as open source. I have a wife, a son and a real life in Hamm, Germany. In my part-time I enjoy making games, music and acting. (He/him)
All non-primitives are passed by reference in es, so we're effectively passing the same array to the sort function. That's why the array is sorted afterwards. The solution would be to clone the array to a new variable before sorting it (i.e. by using the spread operator const larr = [...arr])
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (1)
All non-primitives are passed by reference in es, so we're effectively passing the same array to the sort function. That's why the array is sorted afterwards. The solution would be to clone the array to a new variable before sorting it (i.e. by using the spread operator
const larr = [...arr]
)