Post your Palindrome Checker solutions here!

Kept mine simple, all uppercase, removed extra characters, then flipped it around to check for palindrome

function palindrome(str) {
  var palin = str.toUpperCase().replace(/[\W_]/gi,"");
  var result = palin.split('').reverse().join('');
  return palin === result;
}

palindrome("eye");

console.log(palindrome("level"))
3 Likes

Nice one Dan,

similar to mine. :+1:t5:

Welcome @danc2947636

Great solution!!

You also could also dispense with i flag and var keyword (const is enough there).

const palin = str.toUpperCase().replace(/[\W_]/g, "");

Keep the good work and good luck!!

Hi all! Here’s my code for the palindrome project. I put the guidelines of the rules in comments of my code.

// THE STEPS FOR PROJECT ARE:
// 1. Receive words (from input/user)
// 1a. Palindromes are words that can be spelled backwards and forwards; it doesn’t count spacing or punctuation
// 2. Remove ALL Non-Alphanumberic Characters (punctuation, spaces, symbols)
// 2a. Turn everything into the same case
// 3. Check words and confirm that they are/aren’t palindromes
// 4. Code needs to PASS varying formats of the words. ie: racecar, RaceCar, and race CAR.
// 5. Codes needs to PASS strings w/ special symbols. ie: 2A33a2, 2A3 3a2, and 2_A33#A2y

function removeNonAlpha(str) {
// step 2
return str.replace(/[\W_]/g, “”);
}
function sameCaseStr(str) {
// step 2a
return str.toString().toLowerCase();
}
function reverseString(str) {
// step 3
return str.toString().split(“”).reverse().join(“”);
}
function palindrome(str) {
// removes non-alphanumeric characters
var nonAlphaString = removeNonAlpha(str);

// makes case in string all lowercase
var lowerCaseString = sameCaseStr(nonAlphaString);
// check/confirm if words are palindromes
var reservedString = reverseString(lowerCaseString);
// compare string; if the same, return true
console.log(`Is ${lowerCaseString} the palindrome of ${reservedString}?`)

return lowerCaseString === reservedString;

}

palindrome(“t en e t”);

1 Like

Well done @emdubbsdev!!

Remember that if you select your code and hit the icon </> it would be easier to visualize your code for everyone.

Keep the good work!! Happy coding!

1 Like

I decided to solve it without using methods like .join since at this point we did not learn stuff like that. I will improve the code later.

function palindrome(str) {
  let result = "";
  //looping through the string
  for (let i = str.length - 1; i >= 0; i--) {
    result = result + str[i];
  }
  //cleaning the string and result to discard special characters 
  let newResult = result.replace(/[^a-z0-9]/gi, "");
  let newStr = str.replace(/[^a-z0-9]/gi, "");
  if (newStr.toLowerCase() !== newResult.toLowerCase()) {
    return false;
  }
  return true;
}

palindrome("not a palindrome");
1 Like

Hi @adnanahmad2926951

Great job! Yeah! That is a good way to improve your solving problems skills, limiting yourself to the basic JS syntax.

Keep the good work and happy coding!!

thanks for letting me know! somehow i missed that button lol

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