- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rearranging digits to form the greatest number using JavaScript
Problem
We are required to write a JavaScript function that takes in one positive three-digit integer and rearranges its digits to get the maximum possible number.
Example
Following is the code −
const num = 149; const maxRedigit = function(num) { if(num < 100 || num > 999) return null return +num .toString() .split('') .sort((a, b) => b - a) .join('') }; console.log(maxRedigit(num));
Output
941
- Related Articles
- Form the greatest 5-digit number using three different digits.
- Replacing digits to form binary using JavaScript
- Rotate number to form the maximum number using JavaScript
- List all the numbers by rearranging the digits of 1546.
- Find the difference between the greatest and the least number that can be written using the digits 6,2,7,4,3.
- Find the greatest number of two digits which is a perfect square.
- Find the greatest number of 5 digits which is a perfect square.
- Find the greatest number of 4-digits which is a perfect square.
- Find the greatest number of three digits which is a perfect square.
- Reversed array of digits from number using JavaScript
- Find the number of whole numbers between the smallest and the greatest number of 2 digits.
- Rearranging array elements in JavaScript
- Changing second half of string number digits to zero using JavaScript
- Greatest digit of a number in JavaScript
- Maximize the number by rearranging bits in C++

Advertisements