Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 406 Bytes

check-if-string-is-a-palindrome.md

File metadata and controls

16 lines (14 loc) · 406 Bytes
title description author tags
Check if String is a Palindrome
Checks whether a given string is a palindrome.
axorax
check,palindrome,string
function isPalindrome(str) {
  const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
  return cleanStr === cleanStr.split('').reverse().join('');
}

// Example usage:
isPalindrome('A man, a plan, a canal, Panama'); // Returns: true