DEV Community

Discussion on: 1 line of code: How to sort an array by descending order

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Errr, why sort it one way, then reverse it? Why not just:

const sortDesc = arr =>  [...arr].sort((a, b) => b - a)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
martinkr profile image
Martin Krause

Thank you for the suggestion.

It is a nice improvement. I will update the article and code!