
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Returning number with increasing digits. in JavaScript
Problem
We are required to write a JavaScript function that takes in a number n. Our function should return it with its digits in descending order. Essentially, we should rearrange the digits to create the highest possible number.
Example
Following is the code −
const num = 5423267; const arrangeInDescending = (num = 1) => { const str = String(num); const arr = str.split(''); arr.sort((a, b) => { return +b - +a; }); const newStr = arr.join(''); const res = Number(newStr); return res; }; console.log(arrangeInDescending(num));
Output
Following is the console output −
7654322
- Related Articles
- Returning number of digits in factorial of a number in JavaScript
- Just smaller number with monotone digits in JavaScript
- Returning only odd number from array in JavaScript
- Monotone Increasing Digits in C++
- Returning the nth even number using JavaScript
- Fetch Numbers with Even Number of Digits JavaScript
- Returning the expanded form of a number in JavaScript
- Total number of longest increasing sequences in JavaScript
- Returning the highest number from object properties value – JavaScript
- Finding product of Number digits in JavaScript
- Separating digits of a number in JavaScript
- Number Split into individual digits in JavaScript
- Finding the immediate bigger number formed with the same digits in JavaScript
- Reversing the bits of a decimal number and returning new decimal number in JavaScript
- Python Program to extracts elements from a list with digits in increasing order

Advertisements