Solving Palindrome Number

Sean Ransonette
2 min readNov 10, 2021

I have been doing my best to practice algorithms as much as possible. I am mostly sticking to easy level LeetCode problems at the moment. Recently I solved a problem called Palindrome Number. The surface level idea is you just need to prove if a number of set of numbers are palindromes.

Upon figuring out if the number is a palindrome we must return a Boolean true of false.

Just for reference here is the starting code.

The first step I did was to create a variable to compare to x, the original number and using the toString() and split(‘ ‘) methods.

Let reverse = x.toString().split(‘ ‘)

This would separate all integers represented by x by quotes.

Using just two more methods we will have our reversed comparable variable

Let reverse = x.toString().split(‘ ‘).reverse().join(‘ ‘)

Of course the reverse() method does just exactly as it states and join(‘ ‘) re-connects the integers as they originally were except now in reverse.

Now we just need to compare our now reversed variable aptly name reverse to the original x.

I did this by simply

return(x.toString() === reverse)

Using === we are able to return true or false as requested.

My final code

--

--