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