Skip to content

Instantly share code, notes, and snippets.

@ohaal
Created December 7, 2015 14:06
Show Gist options
  • Save ohaal/1af092ff621b4107bea8 to your computer and use it in GitHub Desktop.
Save ohaal/1af092ff621b4107bea8 to your computer and use it in GitHub Desktop.
Reverse number algorithm (123 -> 321)
function reverseNumber(input) {
var reversedNum = 0;
while (input !== 0) {
reversedNum = reversedNum * 10 + input % 10;
input = Math.floor(input / 10);
}
return reversedNum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment