I have attempted to create a function to determine if a number is a palindrome, but it seems to be malfunctioning. The concept is simple - splitting the number into two halves, comparing them, and reversing one half to check for symmetry.
function palindromeChecker(number) {
let numArray = String(number).split('');
let firstHalf = numArray.slice(0, numArray.length / 2);
let secondHalf = numArray.slice(numArray.length / 2, numArray.length);
if (secondHalf.length > firstHalf.length) {
secondHalf.shift();
}
console.log(firstHalf)
console.log(secondHalf.reverse())
return firstHalf == secondHalf.reverse();
}
console.log(palindromeChecker(1234321));
Although I was optimistic about the outcome, viewing both arrays and the final boolean result displayed:
[ '1', '2', '3' ]
[ '1', '2', '3' ]
false
If anyone can shed light on this issue, I would greatly appreciate it. Thank you!