Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more

Your code is good and possibly faster but I think this is a lot shorter and somewhat easier to understand.

Code
Diff
  • function descendingOrder(n){
      return Number(String(n).split('').sort(function(a, b){return b-a}).join(''));
    }
  • 11 function descendingOrder(n){
    2- let x= n.toString();
    3- let arr = x.split('');
    4- let N = arr.length;
    5-
    6- if (n.length === 1) {
    7- return parseInt(n, 10);
    8- }
    9-
    10- for (let i = 0; i < N; i++) {
    11-
    12- for (let j = 0; j < N-i-1; j++) {
    13- if (arr[j] < arr[j+1]) {
    14- let k = arr[j];
    15- arr[j] = arr[j+1];
    16- arr[j+1] = k;
    17- }
    18- }
    19- }
    20-
    21- n = arr.join('');
    22- n = parseInt(n, 10);
    23- return n;
    2+ return Number(String(n).split('').sort(function(a, b){return b-a}).join(''));
    2424 }