Tip 9 Avoid Sort Confusion with the Spread Operator

In this tip, you’ll learn how to use the spread operator to sort an array multiple times while getting the same result.

You’ve seen by now that you can replace many mutating functions with the spread operator. What should you do when there’s a function that you can’t easily replace? The answer is fairly simple: Use the spread operator to create a copy of the original array, and then mutate that one.

Don’t let the simplicity of the answer fool you. Mutation bugs can sneak up when you least expect them.

This comes up in applications that have tabular sorting data. If you haven’t written an application that displays tabular data, wait around—I guarantee you’ll do it. And the minute you create ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.