...

/

Tip 9: Avoid Sort Confusion with the Spread Operator

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.

Sorting tabular data

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

Access this course and 1400+ top-rated courses and projects.