js reverse int in descending order code example
Example 1: js reverse int in descending order
function descendingOrder(n){
return parseInt(String(n).split('').sort().reverse().join(''));
}
console.log(descendingOrder(15));
console.log(descendingOrder(22314));
Example 2: js reverse int in descending order
function descendingOrder(n){
let reversed = n.toString().split("").sort((a, b) => b - a).join('');
return parseInt(reversed) * Math.sign(n);
}
console.log(descendingOrder(463));
console.log(descendingOrder(223744));