Created
February 15, 2022 07:58
-
-
Save r17x/5285fa0febda5a3834325fcd7340f77e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @param {Number} n | |
* @return {Number} | |
* @example | |
* | |
* reverseNumber(123) // 321 | |
* reverseNumber(212) // 212 | |
* reverseNumber(123456789) // 987654321 | |
*/ | |
const reverseNumber = (input) => { | |
let result = 0; | |
while (input > 0) { | |
const lastNum = input % 10; | |
result = (result * 10) + lastNum; | |
input = (input / 10) | 0; // parseInt | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment