Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function isPalindrome(number) {
  2. let divisor = 1;
  3.  
  4. // Find the appropriate divisor
  5. // to extract the leading digit
  6. while (number / divisor >= 10) {
  7. divisor *= 10;
  8. }
  9.  
  10. while (number !== 0) {
  11. const leading = Math.floor(number / divisor);
  12. const trailing = number % 10;
  13.  
  14. if (leading !== trailing) {
  15. return false;
  16. }
  17.  
  18. // Remove the leading and trailing digits from the number
  19. number = Math.floor(number % divisor / 10);
  20.  
  21. // Reduce the divisor by a factor of 2 since we dropped 2 digits
  22. divisor /= 100;
  23. }
  24.  
  25. return true;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement