Created
November 9, 2018 00:32
-
-
Save AminBusiness/29d0d0c23194db564ee0049ce7308158 to your computer and use it in GitHub Desktop.
// source https://jsbin.com/gavovuh
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
<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> |
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
// 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