Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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
Advertisements