Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isPalindrome(number) {
- let divisor = 1;
- // Find the appropriate divisor
- // to extract the leading digit
- while (number / divisor >= 10) {
- divisor *= 10;
- }
- while (number !== 0) {
- const leading = Math.floor(number / divisor);
- const trailing = number % 10;
- if (leading !== trailing) {
- return false;
- }
- // Remove the leading and trailing digits from the number
- number = Math.floor(number % divisor / 10);
- // Reduce the divisor by a factor of 2 since we dropped 2 digits
- divisor /= 100;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement