The task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.
Examples:
Given Input: 21445
-> Expected Output: 54421
Given Input: 145263
-> Expected Output: 654321
Given Input: 1254859723
-> Expected Output: 9875543221
My thinking is to break the number into individual strings and push into an array then sort them descending way then make it a number again. But is there a better way to handle this?
+num.toString().match(/\d/g).sort((a,b)=>b>a).join('')
+number.toString().split("").sort((p,c)=>p<c).join("");