Created
January 3, 2018 07:58
-
-
Save eldyvoon/cdc189b908a243e9b9dde349a718c6c8 to your computer and use it in GitHub Desktop.
Reverse Int in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//specs | |
reverseInt(12); //21 | |
reverseInt(500); //5 | |
reverseInt(-15); //-51 | |
function reverseInt(n) { | |
const reversed = n.toString().split('').reverse().join('') | |
return parseInt(reversed) * Math.sign(n) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment