- 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
Finding the just bigger number formed by same digits in JavaScript
Problem
We are required to write a JavaScript function that takes in a number, num, as the first and the only argument.
Our function should find and return a number such that it contains only and all the digits of the input number and is just bigger than the input number
If there exists no such number, our function should return -1.
For example, if the input to the function is −
const num = 5656;
Then the output should be −
const output = 5665;
Output Explanation
Because 5665 contains only and all digits of 5656 and is just greater than 5656.
Example
Following is the code &mius;
const num = 5656; const justBigger = (num) => { const sorted = num => ('' + num).split('').sort((a, b) => b - a); const max = +sorted(num).join('') for (let i = num + 1; i <= max; i++) { if (max === +sorted(i).join('')){ return i; } }; return -1; } console.log(justBigger(num));
Output
Following is the console output −
5665
- Related Articles
- Finding the immediate bigger number formed with the same digits in JavaScript
- Just smaller number with monotone digits in JavaScript
- Finding product of Number digits in JavaScript
- JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript
- Find the Largest Cube formed by Deleting minimum Digits from a number in Python
- Find the Largest Cube formed by Deleting minimum Digits from a number in C++
- How many numbers can be formed by arranging the digits of the number 211 ?
- Recursive sum of digits of a number formed by repeated appends in C++
- Summing up digits and finding nearest prime in JavaScript
- Smallest prime number just greater than the specified number in JavaScript
- In which case is a bigger Shadow formed?
- Finding Gapful number in JavaScript
- Finding the smallest fitting number in JavaScript
- Finding the nth prime number in JavaScript
- Finding a pair that is divisible by some number in JavaScript

Advertisements