Answers for "palindrome javascript"

9

palindrome in javascript

function palindrome(str) {

    var len = str.length;
    var mid = Math.floor(len/2);

    for ( var i = 0; i < mid; i++ ) {
        if (str[i] !== str[len - 1 - i]) {
            return false;
        }
    }

    return true;
}
Posted by: Guest on November-13-2020
0

how to check palindrome in javascript for lowercase and uppercase

function palindrome(str) {
  var re = /[\W_]/g;
  var lowRegStr = str.toLowerCase().replace(re, '');
  var reverseStr = lowRegStr.split('').reverse().join(''); 
  return reverseStr === lowRegStr;
}
palindrome("A man, a plan, a canal. Panama");
Posted by: Guest on July-27-2020
0

palindrome js

const palindrome = (str) => {
  var text = str.replace(/[.,'!?\- \"]/g, "")
  return text.search(
    new RegExp(
      text
        .split("")
        .reverse()
        .join(""),
      "i"
    )
  ) !== -1;
}
  
//or
function palindrome(str) {
  let text = str.replace(/[.,'!?\- \"]/g, "").toUpperCase();
  for (let i = 0; i > text.length/2; i++) {
    if (text.charAt(i) !== text.charAt(text.length - 1 - i)) {
      return false;
    }
  }
  return true;
}
console.log(palindrome("Able was I, ere I saw elba.")); //logs 'true'
Posted by: Guest on January-05-2021
0

javascript palindrome check

function palindrome(str) {
 var re = /[^A-Za-z0-9]/g;
 str = str.toLowerCase().replace(re, '');
 var len = str.length;
 for (var i = 0; i < len/2; i++) {
   if (str[i] !== str[len - 1 - i]) {
       return false;
   }
 }
 return true;
}
palindrome("A man, a plan, a canal. Panama");
Posted by: Guest on December-10-2020
0

palindrome javascript

function palindrome(str) {
 var splitted = str.split("");
 var reversed = splitted.reverse("");
 var joined = reversed.join("");
 return joined.toLowerCase().replace(/[^0-9a-z]/gi, '') == str.toLowerCase().replace(/[^0-9a-z]/gi, '')
}
Posted by: Guest on September-10-2020
0

palindrome javascript

const reverseString = string.split('').reverse().join('');
Posted by: Guest on April-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language