Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Created January 5, 2021 16:36
Show Gist options
  • Save Jagathishrex/268c9f6f331ab81d0b23b418c265aca2 to your computer and use it in GitHub Desktop.
Save Jagathishrex/268c9f6f331ab81d0b23b418c265aca2 to your computer and use it in GitHub Desktop.
function reverseInt(n) {
let reversedInteger = n.toString().split('').reverse().join('');
return parseInt(reversedInteger) * Math.sign(n);
}
console.log(reverseInt(-12)); // -21
console.log(reverseInt(-1)); // -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment