Palindrome Number
Used JavaScript for the challenge
Today's challenge was a bit more fun, and I had a clear idea immediately after I saw the question. This was the fastest I have solved since the start of the challenge.
Thought process
The following was my thought process after reading the question and understanding it:
Convert the integer to a string.
Reverse the string
Use different string and array methods
Convert it back to an integer.
Compare the original input value to the reversed value.
If they match, return true, else, return false.
Implementation
These were the steps followed to achieve the implementation:
Created a variable reversedX which held the result of the reversed integer.
Applied ""+n method which converted the input integer (x) to a string.
Used the split() method which splitted the string to individual elements.
Used the reverse() method.
Used the join() method to join the element back to a string.
Used the parseInt() method to convert the string back to integer. This step was taken to make it possible to compare using the strict equality operator ===
Used an if block to check if the input integer (x) was equal to the reversed integer (reversedX).
If equal, the block returned true, else, it returned false.
What I learnt
Learnt about another method I can use to convert integers to strings which was the ""+n
method
Conclusion
Generally, I had more fun doing today's challenge. My code passed about 11510 test cases in 331ms using 51.3MB memory space
Thank you for reading through!
Day three(3) down, and Seven more days to go!
You can follow me on Twitter