Created
December 28, 2023 05:43
-
-
Save petergi/18d4789ecd7dcf83efb9a486d75e98d5 to your computer and use it in GitHub Desktop.
Checks if the given string is a palindrome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if a given string is a palindrome. | |
* | |
* @param {string} str - The string to be checked. | |
* @return {boolean} Returns true if the string is a palindrome, false otherwise. | |
*/ | |
function isPalindrome(str) { | |
const formattedStr = str.toLowerCase().replace(/[\W_]/g, ""); | |
const reversedStr = formattedStr.split("").reverse().join(""); | |
return formattedStr === reversedStr; | |
} | |
palindrome("taco cat") //= true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment