Skip to main content

Command Palette

Search for a command to run...

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

Updated
β€’1 min read
9. Palindrome Number - JavaScript Solution - by Abu Saleh Faysal
A

Experienced software engineer with a demonstrated history of working in several tech startups. Skilled in Front-End Development using Bootstrap, TailwindCSS, JavaScript, TypeScript, React, Redux, Firebase. Strong software professional with a Bachelor of Science focused in Computer Science and Engineering from BRAC University.

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.

Runtime: 330 ms

Memory: 51.1 MB

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

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

πŸ‘‰ YouTube Channel Link: youtube.com/channel/UCW_09Nbobf4URLkAlEo84sw

πŸ‘‰ PlayList Link: youtube.com/playlist?list=PLUnklBXn8NSefCpB..

πŸ‘‰ Connect with me (LinkedIn): linkedin.com/in/abusalehfaysal

πŸ‘‰ Follow our LinkedIn Page: linkedin.com/company/thebacklogprogrammer

πŸ‘‰ Like our Facebook page: facebook.com/thebacklogprogrammer

πŸ‘‰ Join our community (Facebook group): facebook.com/groups/5500588936676942

πŸ‘‰ Follow me at: facebook.com/AbuSalehFaysal10

πŸ‘‰ Twitter: twitter.com/AbuSalehFaysal

πŸ‘‰ Abu Saleh Faysal’s Blog: abusalehfaysal.hashnode.dev

πŸ‘‰ Hasnode: hashnode.com/@AbuSalehFaysal

πŸ‘‰ Dev Community: dev.to/abusalehfaysal

πŸ‘‰ freeCodeCamp: freecodecamp.org/abusalehfaysal

πŸ‘‰ Medium: abusalehfaysal.medium.com

πŸ‘‰ GitHub: github.com/AbuSalehFaysal

πŸ‘‰ GitLab: gitlab.com/AbuSalehFaysal