
- 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
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
- Related Articles
- Rearranging digits to form the greatest number using JavaScript
- Return the maximum number in each array using map JavaScript
- Finding the maximum number using at most one swap in JavaScript
- Maximum difference between a number JavaScript
- C program to rotate the bits for a given number
- JavaScript Finding the third maximum number in an array
- Returning the expanded form of a number in JavaScript
- Finding next prime number to a given number using JavaScript
- Return the difference between the maximum & minimum number formed out of the number n in JavaScript
- Finding maximum number from two arrays in JavaScript
- Obtaining maximum number via rotating digits in JavaScript
- Finding the third maximum number within an array in JavaScript
- Splitting number to contain continuous odd or even number using JavaScript
- Golang Program to find the minimum and maximum number, using binary operations.
- Finding the largest 5 digit number within the input number using JavaScript

Advertisements