DEV Community

Cover image for codewar day3

Posted on

codewar day3

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.

Input: 42145 Output: 54421

Input: 145263 Output: 654321

Input: 123456789 Output: 987654321

then my solve :

const sortnumber = n => {
  let data = parseInt(
      .replace(/,/g, "")
  return data;
Enter fullscreen mode Exit fullscreen mode

i use some string, number and array prototype i learn a lot from
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('')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)