loading...
Cover image for codewar day3

codewar day3

g33knoob profile image G33kNoob ・1 min read

today the problem like this :
Your task is to make a function that can take any non-negative integer as a argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.

Examples:
Input: 42145 Output: 54421

Input: 145263 Output: 654321

Input: 123456789 Output: 987654321

then my solve :

const sortnumber = n => {
  let data = parseInt(
    n
      .toString()
      .split("")
      .sort()
      .reverse()
      .join()
      .replace(/,/g, "")
  );
  return data;
};

i use some string, number and array prototype i learn a lot from developer.mozilla.org
i learning how the faster solve the problem, solve it with 'logic', then find how to cooding it :)
thanks codewar and mozilla developer

anyway other sorter solving like this

function descendingOrder(n){
  return +(n+'').split('').sort().reverse().join('')
}

Posted on by:

g33knoob profile

G33kNoob

@g33knoob

express js, vue js

Discussion

markdown guide