 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Finding difference of greatest and the smallest digit in a number - JavaScript
We are required to write a JavaScript function that takes in a number and returns the difference between the greatest and the smallest digit present in it.
For example: If the number is 5464676, then the smallest digit here is 4 and the greatest is 7
Hence, our output should be 3
Example
Let’s write the code for this function −
const num = 44353456; const difference = (num, min = Infinity, max = -Infinity) => {    if(num){       const digit = num % 10;       return difference(Math.floor(num / 10), Math.min(digit, min),       Math.max(digit, max));    };    return max - min; }; console.log(difference(num));  Output
The output in the console: −
3
Advertisements
 