// Function to reverse Number
function reverseNum(n) {
let r = n.toString().split('').reverse().join('');
return Math.sign(n) * parseInt(r);
}
// Call
reverseNum(-267);
reverseNum(31522);
// Outputs
-762
22513
// how to reverse number in javascript
let number = 12345;
let reverse = parseInt(number.toString().split('').reverse().join(''));
console.log(reverse);
// Output:
// 54321
let rev = 0;
let num = 123456;
let lastDigit;
while(num != 0){
lastDigit = num % 10;
rev = rev * 10 + lastDigit;
num = Math.floor(num/10);
}
console.log("Reverse number : "+rev);
const num = 3849;
function reverseGivenInteger(num) {
return Number(String(num).split('').reverse().join(''))
}
console.log(`Reversed integer is: ${reverseGivenInteger(num)}`)
const reversedNum = num => parseFloat(num.toString().split('').reverse().join('')) * Math.sign(num)