Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Palindrome Checker

// The Setup
function palindrome(str) {

  // Using Regex to remove all the special character, converted all the string to lowercase to ease working with and assign it to a new variable 
  let newStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();

  // Split the string, reverse, join then assign it to a new variable
  let revStr = newStr.split('').reverse().join('');

  // return their value
  return newStr === revStr;

}

palindrome("A man, a plan, a canal. Panama");
Source by www.linkedin.com #
 
PREVIOUS NEXT
Tagged: #Palindrome #Checker
ADD COMMENT
Topic
Name
6+3 =