Q:

Break the string and arrange it in highest order

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?

A:

You can split the String on "" and map it to convert each item to a number. Then you can use Array.prototype.sort to put it in descending order. If you want it as a String you can join it on "".

var str = "92345";
var numStr = str.split('').map(function(item) {
    return +item;
});
var orderedArr = numStr.sort(function(a,b){
 return b-a;
});
var orderedStr = orderedArr.join("");
console.log(orderedArr);
console.log(orderedStr);

A shorter way would be to use the unary operator to convert the String to a number, split it on "", sort it, and join it on "".

var str = "91785";
function orderDesc(str){
  return +str.split('').sort((a,b)=>b-a).join('');
}
console.log(orderDesc(str));

