Created
September 16, 2020 20:42
-
-
Save dabsclement/2a6d604c8abef0075761d233a752283a to your computer and use it in GitHub Desktop.
palindrome-number
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} x | |
* @return {boolean} | |
*/ | |
const isPalindrome = x => { | |
if (x < 0) return false | |
let reverse = 0, y = x | |
while (y > 0) { | |
const lastNumber = y % 10 | |
reverse = (reverse * 10) + lastNumber | |
y = (y / 10) | 0 | |
} | |
return x === reverse | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment