javascript function that checks whether a passed string is palindrome or not

Solutions on MaxInterview for javascript function that checks whether a passed string is palindrome or not by the best coders in the world

showing results for - "javascript function that checks whether a passed string is palindrome or not"
Lainey
13 May 2019
1function palindrome(str) {
2  // Step 1. Lowercase the string and use the RegExp to remove unwanted characters from it
3  var re = /[\W_]/g; // or var re = /[^A-Za-z0-9]/g;
4  
5  var lowRegStr = str.toLowerCase().replace(re, '');
6  // str.toLowerCase() = "A man, a plan, a canal. Panama".toLowerCase() = "a man, a plan, a canal. panama"
7  // str.replace(/[\W_]/g, '') = "a man, a plan, a canal. panama".replace(/[\W_]/g, '') = "amanaplanacanalpanama"
8  // var lowRegStr = "amanaplanacanalpanama";
9     
10  // Step 2. Use the same chaining methods with built-in functions from the previous article 'Three Ways to Reverse a String in JavaScript'
11  var reverseStr = lowRegStr.split('').reverse().join(''); 
12  // lowRegStr.split('') = "amanaplanacanalpanama".split('') = ["a", "m", "a", "n", "a", "p", "l", "a", "n", "a", "c", "a", "n", "a", "l", "p", "a", "n", "a", "m", "a"]
13  // ["a", "m", "a", "n", "a", "p", "l", "a", "n", "a", "c", "a", "n", "a", "l", "p", "a", "n", "a", "m", "a"].reverse() = ["a", "m", "a", "n", "a", "p", "l", "a", "n", "a", "c", "a", "n", "a", "l", "p", "a", "n", "a", "m", "a"]
14  // ["a", "m", "a", "n", "a", "p", "l", "a", "n", "a", "c", "a", "n", "a", "l", "p", "a", "n", "a", "m", "a"].join('') = "amanaplanacanalpanama"
15  // So, "amanaplanacanalpanama".split('').reverse().join('') = "amanaplanacanalpanama";
16  // And, var reverseStr = "amanaplanacanalpanama";
17   
18  // Step 3. Check if reverseStr is strictly equals to lowRegStr and return a Boolean
19  return reverseStr === lowRegStr; // "amanaplanacanalpanama" === "amanaplanacanalpanama"? => true
20}
21 
22palindrome("A man, a plan, a canal. Panama");
queries leading to this page
string is palindrome or not in javascriptpalindrome checker in javascriptjavascript code palindrome7 write a function which will check if a given string is palindrome or not javascriptgiven the string check if it is a palindrome javascriptcheck palindrome in javascriptpalindrome check javascriptpalindrome number check in javascriptwrite a function that tests whether a string is a palindrome javascript pseudocodehow to check if a string is palindrome in javascriptcheck whether a string is palindrome or not in javascriptjs code for finding palindromecheck if word is palindrome javascriptjavascript function that returns true if the given string is a palindrome otherwisejs ispalindromepalindrome number in javascript directlyjavascript palindrome programapa itu palindrome di jshow to check if word is palindrome in javascript recursionpalindrom javascriptwhat happens when you encrypt an empty stringjavascript how to check if its a palindromejavascript check if a string is a palindromepalindrome check in jqueryispalindrome jscheck if a string is palidrome or not in javascriptjavascript ispalindromejs check if a string can be a palindromepalindrone javascriptcheck if a word is a palindrome javascriptfunction to check if a substring contains a palindrome in javascriptjavascript find palindromehow to write function that checks if a given string 28case insensitive 29 is a palindrome in javascriptjs palindromepalindrome javascript functionprogram to find occurrences of palindrome words in string using javascripthow to check for a palindrome in javascriptjavascrpit code that determines a palindrome word in a sentencejs check if palindromejavascript check for a palindromepalindrome node jshow to say or in c 23check if the word is palidrome in javascriptpalindrome string javascriptfunction palindrome 28word 29 javascriptpalindrome checker jspalindrome number in javascriptif element not found do this action in seleniumjavascript find palindrome mappalindrome jsjavascript recursive check if word is palindromeis a phrase polindrome jsa palindrome is a word 2c phrase 2c or number that is spelled the same forward and backward javascriptpalindrome program in javascript without using reverse functionpalindrome checker javascriptnode js wap to find palindrome how to return palindromes out of a string jsis word a palindrome javascriptthe file you asked for does not exist javascriptpalindrome with javascriptcheck for palindrome javascriptstring palindrome in jsjs palindrome codejavascript palindrome exampleis palindrome algorithm javascript every 28 29 explainedcheck palindrome javascriptjavascript write a function called ispalindrome that accepts a single string argument 2c then returns true or false depending upon whether or not the string is a palindrome check if words are palindrome jscheck palindrome jsjavascript palindrome questioncheck if a string is palindrome in javascript without using string functionsjavascript if and ornode js check for palindromepalindrome function javascriptpalindrom question javascriptwhile string files on server what should we do if the file names are not uniquecount palindrome words in a sentence using javascriptpalindrome in javascripthow to get a palindrome jsjavascript palindrome detectorjavascript if a sentence has the letters mirrored but has different spaces 2c then it 27s not a pure palindromejavascript palindrome checkerpalindrome examples in javascriptjs is palindromepalindrome check in javascriptpalindrome code javascript2 write a javascript function that checks whether a passed string is palindrome or not 3fwrite a function that checks if a given word is a palindrome javascriptjavascript implement a method which receives a string and checks whether it is palindrome on not what is the difference between reverse and palindrome in jschecking if integer is palindrome js javascript check if palindromecheck if string is palindrome in javascriptchecking palindrome in javascriptpallindrome in javascriptlearn palindrome code javascriptjavascript palindrome stringpalndrome jsaltername palindrome code in javascriptfind palindrome javascripthow to check if the word is a palindrome or not in jspalindrome word javascriptfind palindrome in string javascript palindrom in jscheck if a string is palindrome in javascripthow to return every palindromes from a string jspalindrome javascriptcreate a recursive function that determines whether a word is a palindrome or not javascriptpalindrome javascript question sentencejavascript application that check if word is palindromejs palindrome wordspalindrome algorithm javascriptchecking palindrome with map palindrome program in javascript how to ispalindrome javascriptwrite a program to find all the palindrome words in a string using javascripthow to check given string is palin drome or not in jshow to check something is palindrome word in jswhat happens if you try and split a string at something that doesn 27t exist javapalindrome javascript devbreaking a palindrome javascriptpalindromes in javascriptjs ispalindrome for loopjavascript code that determines a palindrome word in a sentencewrite a javascript function that checks whether a passed string is palindrome or not 3fhow to make a palindrome in javascript with out javascript methodsstring palindrome jscheck a string is palindrome or not jssee if the word is a palindrome jspalindrome string in javascripthow to find palindrome word in a sentence using javascriptpalindrome number javascripthow to check given string is palindrome or not in javascriptpalindrome checker in one line code javascriptjavascript palindromejavascript palindrome without regexcheck if string is palindrom javascritpfind palindrome word from below string array in javascriptfunction javascript get palindromehow to check palindrome in javascriptfunction to check if string is palindrome javascriptreturn reversed palindrome phrase jshow to find palindromws jspalindrome program in javascriptpalindrome in javascript without using string functionjs find palindromevalid palindrome javascripthow to extract palindrome word in an sentence using javascriptstring palindrome in javascriptispalindrome javascriptis palindrome check in javascripthow do you detect whether or not a word is a palindrome in javascriptgiven word is palindromw or not in javascriptcheck if string is palindrome javascriptpalindrom jsjs function that takes in a single word as a string and returns true if it e2 80 99s a palindromewrite a function checkpalindrome that accepts a single argument 2c a string the function should return true 28boolean 29 if the string is a palindrome 2c false if it is not make sure your function will give the correct answer for words with capital letters check if string is palindrome jspalindrome numbers true jscheck to see if a word is a palindrome jsextract palindrome word in a sentence using javascriptif we want define style for an unique element 2c then which css selector will we use 3fjavascript function that checks whether a passed string is palindrome or not