
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements