

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Replacing digits to form binary using JavaScript
- Rotate number to form the maximum number using JavaScript
- Greatest digit of a number in JavaScript
- Maximize the number by rearranging bits in C++
- Rearranging array elements in JavaScript
- Reversed array of digits from number using JavaScript
- Rearranging cards into groups in JavaScript
- Finding the greatest and smallest number in a space separated string of numbers using JavaScript
- Greatest number in a dynamically typed array in JavaScript
- Changing second half of string number digits to zero using JavaScript
- Number of digits that divide the complete number in JavaScript
- Rearranging elements of an array in JavaScript
- Finding difference of greatest and the smallest digit in a number - JavaScript
- Subarray with the greatest product in JavaScript
- Finding a greatest number in a nested array in JavaScript
Advertisements