Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const isPalindrome = n => {
- if (n < 0) { return false; }
- let num = Math.abs(n);
- const arr = [];
- let i = 1;
- while (num > 0) {
- const min = num % (10 ** i);
- num = num - min;
- i++;
- arr.push(min);
- }
- i = i - 2;
- let j = 0;
- return n === arr.reduce((res, x) => {
- const add = (x/ (10 ** j)) * (10 ** i);
- res += add;
- i--;
- j++;
- return res;
- }, 0);
- };
- console.log(isPalindrome(121));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement