DEV Community

Cover image for codewar day3
G33kNoob
G33kNoob

Posted on

2 2

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.

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;
};
Enter fullscreen mode Exit fullscreen mode

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('')
}
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay