reverseInt(15) //--> 51
reverseInt(981) //--> 189
reverseInt(500) //--> 5
reverseInt(-15) //--> -15
reverseInt(-90) //--> -9
My Solution
function reverseInt(n) {
const reversed = n
.toString()
.split('')
.reduce((acc, cur) => cur + acc, '');
return Math.sign(n) * parseInt(reversed);
}
SG Solution 1
function reverseInt(n) {
const reversed = n
.toString()
.split('')
.reverse()
.join('');
return Math.sign(n) * parseInt(reversed);
}