Palindrome Checker - JavaScript Algorithm & Data Structure Project freeCodeCamp

Palindrome Checker Conditions

Return true if the given string is a palindrome. Otherwise, return false.

A palindrome is a word or sentence that’s spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

Note: You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.

Answer:

				
					function palindrome(str) {
  let newStr = str.toLowerCase().replace(/[^a-z0-9+]+/g, '');

  let reverseStr = newStr.split('').reverse().join('')
  if(newStr === reverseStr){
  	return true
  }else{
  	return false;
  }
}
				
			
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp
Share on google
Google+
Share on telegram
Telegram

Leave a Reply

Your email address will not be published.

2 replies on “Palindrome Checker”