reverse numbers js code example
Example 1: reverse number javascript
function reverseNum(n) {
let r = n.toString().split('').reverse().join('');
return Math.sign(n) * parseInt(r);
}
reverseNum(-267);
reverseNum(31522);
-762
22513
Example 2: reverse number in js
function reversedNum(num) {
return (
parseFloat(
num
.toString()
.split('')
.reverse()
.join('')
) * Math.sign(num)
)
}
Example 3: reverse int js
function reverseInt(n) {
const reversed = n.toString().split("").reverse().join("");
return parseInt(reversed) * Math.sign(n);
}