[Full explanation will be added soon.]
AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {number} x
* @return {boolean}
*/
let isPalindrome = function(x) {
if (x < 0) {
return false;
}
return x === reversedInteger(x);
};
let reversedInteger = function(x) {
let reversed = 0;
while (x > 0) {
reversed = (reversed * 10) + (x % 10);
x = Math.floor(x / 10);
}
return reversed;
};