Created
January 4, 2015 17:55
-
-
Save dmi3y/e8fbb84431740657616a to your computer and use it in GitHub Desktop.
invert number mathematically
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
function invert(num) | |
rev = 0 | |
while num >= 10 | |
rev = (rev + num % 10) * 10 | |
num = fld(num, 10) | |
end | |
return (rev + num) | |
end |
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
function invert(num) { | |
var | |
inv = 0; | |
while ( num >= 10 ) { | |
inv = (inv + num % 10) * 10; | |
num = parseInt(num/10); | |
} | |
return (inv + num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment