Skip to content

Instantly share code, notes, and snippets.

@AminBusiness
Created November 9, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AminBusiness/29d0d0c23194db564ee0049ce7308158 to your computer and use it in GitHub Desktop.
Save AminBusiness/29d0d0c23194db564ee0049ce7308158 to your computer and use it in GitHub Desktop.
<script id="jsbin-javascript">
// Challenge 3: Reverse an Int
// Return an integer in reverse
// ex. reverseInt(521) = 125
function reverseInt(int)
{
//Turns the number into a string than it reverses it
const revString = int.toString().split('').reverse().join('');
//Use parse to turn string into an int, works for negative numbers
return parseInt(revString) * Math.sign(int);
}
const output = reverseInt(-12345);
console.log(output);
</script>
<script id="jsbin-source-javascript" type="text/javascript">// Challenge 3: Reverse an Int
// Return an integer in reverse
// ex. reverseInt(521) = 125
function reverseInt(int)
{
//Turns the number into a string than it reverses it
const revString = int.toString().split('').reverse().join('');
//Use parse to turn string into an int, works for negative numbers
return parseInt(revString) * Math.sign(int);
}
const output = reverseInt(-12345);
console.log(output);
</script>
// Challenge 3: Reverse an Int
// Return an integer in reverse
// ex. reverseInt(521) = 125
function reverseInt(int)
{
//Turns the number into a string than it reverses it
const revString = int.toString().split('').reverse().join('');
//Use parse to turn string into an int, works for negative numbers
return parseInt(revString) * Math.sign(int);
}
const output = reverseInt(-12345);
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment