- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Reverse numbers in function without using reverse() method in JavaScript
We are required to write a JavaScript function that takes in a number and returns its reversed number with converting it to an array or string.
Let's write the code for this function −
Example
const num = 234567; const reverseNumber = (num, res = 0) => { if(num){ return reverseNumber(Math.floor(num / 10), (res*10)+(num % 10)); }; return res; }; console.log(reverseNumber(num)); console.log(reverseNumber(53536)); console.log(reverseNumber(76576));
Output
The output in the console will be −
765432 63535 67567
Advertisements