
- 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
Corner digit number difference - JavaScript
We are required to write a JavaScript function that takes in a number, constructs a new number from the first and last digit of that number and returns the difference between the original number and the number thus formed.
For example: If the input is 34567
Then the corner digits number will be −
37
And the output will be −
34530
Example
Following is the code −
const num = 34567; const cornerDifference = num => { let temp = Math.abs(num); let corner = temp % 10; if(temp < 100){ corner = temp; }else{ while(temp >= 10){ temp = Math.floor(temp / 10); }; corner = (temp*10) + corner; }; return num - corner; }; console.log(cornerDifference(num));
Output
Following is the output in the console −
34530
- Related Articles
- Greater possible digit difference of a number in JavaScript
- Finding difference of greatest and the smallest digit in a number - JavaScript
- Negative number digit sum in JavaScript
- Find even odd index digit difference - JavaScript
- Find the difference between the largest 3 digit number and the smallest 6 digit number.
- Find the difference between the largest 8-digit number and the smallest 6-digit number.
- Greatest digit of a number in JavaScript
- Square every digit of a number - JavaScript
- Is the digit divisible by the previous digit of the number in JavaScript
- JavaScript - Find the smallest n digit number or greater
- Digit sum upto a number of digits of a number in JavaScript
- Finding the largest 5 digit number within the input number using JavaScript
- Form a Number Using Corner Digits of Powers
- Sum up a number until it becomes one digit - JavaScript
- Sum up a number until it becomes 1 digit JavaScript

Advertisements