Created
June 22, 2021 20:53
-
-
Save Elijah-trillionz/f412aa3c84a4456d371cbb6f84eacffe to your computer and use it in GitHub Desktop.
Reverse a 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
// 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