It is important to note that with problems like this, developers will have different methods to solve it but I will be using one of the basic ways to solve this with Javascript. Javascript methods I will be using here include toString(), split(), sort(), join() and parseInt(). So basically, our function accepts a "number" input, converts it to a string, and then splits the string into an array, making it possible for us to use the javascript method that deals with sorting. This is because the sort method can't work on a number directly, nor can it work on a string directly but rather on an array, so we are converting to an array first. We then use the join method to convert the array to a string. Finally, the parseInt method converts the string to a number and outputs the number for the user.
const digitInDescendingOrder = (num) => {
// convert input to string
const numString = num.toString();
// convert stringified input to array
const numArray = numString.split('');
// sort array in descending order
numArray.sort((a, b) => b - a);
// convert sorted array to string
const numArrayToString = numArray.join('');
// convert string back to number and return number as an output
return parseInt(numArrayToString);
}
const getDescendingOrder = digitInDescendingOrder(394567812);
console.log('getDescendingOrder', getDescendingOrder);