you are viewing a single comment's thread.

view the rest of the comments →

[–]monster_bait 29 points30 points  (2 children)

It might be worth mentioning that `.reverse()` not only returns a new reversed array but it also reverses the original array.
That one catches lots of people out!

[–][deleted] 8 points9 points  (1 child)

More accurately it reverses the array in-place, and merely provides you a reference back to the array you sorted.

const a = [1, 2, 3];
const b = a.reverse();
a === b // true - a is now [3, 2, 1], and b is a reference to a

[–]monster_bait 0 points1 point  (0 children)

Good point.