Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created June 22, 2021 20:53
Show Gist options
  • Save Elijah-trillionz/f412aa3c84a4456d371cbb6f84eacffe to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/f412aa3c84a4456d371cbb6f84eacffe to your computer and use it in GitHub Desktop.
Reverse a number mathematically
// reversing a number
let givenNum = 4552;
let numInRev = 0;
while (givenNum > 0) {
const lastDigit = Math.floor(givenNum % 10);
numInRev = numInRev * 10 + lastDigit;
givenNum = Math.floor(givenNum / 10);
}
console.log(numInRev);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment