Skip to content

Instantly share code, notes, and snippets.

@dmi3y
Created January 4, 2015 17:55
Show Gist options
  • Save dmi3y/e8fbb84431740657616a to your computer and use it in GitHub Desktop.
Save dmi3y/e8fbb84431740657616a to your computer and use it in GitHub Desktop.
invert number mathematically
function invert(num)
rev = 0
while num >= 10
rev = (rev + num % 10) * 10
num = fld(num, 10)
end
return (rev + num)
end
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