Your code is good and possibly faster but I think this is a lot shorter and somewhat easier to understand.
function descendingOrder(n){ return Number(String(n).split('').sort(function(a, b){return b-a}).join('')); }
- function descendingOrder(n){
let x= n.toString();let arr = x.split('');let N = arr.length;if (n.length === 1) {return parseInt(n, 10);}for (let i = 0; i < N; i++) {for (let j = 0; j < N-i-1; j++) {if (arr[j] < arr[j+1]) {let k = arr[j];arr[j] = arr[j+1];arr[j+1] = k;}}}n = arr.join('');n = parseInt(n, 10);return n;- return Number(String(n).split('').sort(function(a, b){return b-a}).join(''));
- }