![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Rotate number to form the maximum number using JavaScript
Problem
We are required to write a JavaScript function that takes in a number n. Our function is required to return the maximum value by rearranging its digits.
Example
Following is the code −
const num = 124; const rotateToMax = n => { n = n .toString() .split('') .map(el => +el); n.sort((a, b) => return b - a; }); return n .join(''); }; console.log(rotateToMax(num));
Output
421
Advertisements