Javascript help. palindrome

Huzzah! Nice work getting it passing!

One more small hint:

function palindrome(str) {
  let regex = /[\W+\s_]/gi;
  let replacedStr = str
  .replace(regex, '')
  .toLowerCase();
  console.log(replacedStr);
  console.log(Math.floor(replacedStr.length / 2));
  //let count = 0;
  

  for (let i = 0; i < Math.floor(replacedStr.length / 2); i++) {
    console.log("i: " + i);
    console.log(replacedStr.length -1 - i);
    console.log("comparing " + replacedStr.charAt(i) + " and " + replacedStr.charAt(replacedStr.length -1 - i));
    if (replacedStr.charAt(i) == replacedStr.charAt(replacedStr.length -1 - i)) {
/*
      count++;
      console.log('Count:' + count);
      if(count == Math.floor(replacedStr.length / 2)){
        return true
      }
*/
    } else {
      return false
    }
  }
}


console.log("returned result: " + palindrome("racecar"));

What happens if you run this?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.