How to check whether a sentence is palindrome in TypeScript

1 Answer

0 votes
function isSentencePalindrome(str: string) {
    // Change the string into lowercase and remove all non-alphanumeric characters
    str = str.toLowerCase().replace(/[^a-zA-Z0-9]/g, "");
    
    return str === str.split("").reverse().join("");
}

console.log(isSentencePalindrome("Top step's pup's pet spot.") ? "yes" : "no");



 
/*
run:
   
"yes" 
  
*/

 



answered Jul 1, 2024 by avibootz

Related questions

1 answer 120 views
1 answer 119 views
1 answer 123 views
1 answer 125 views
1 answer 116 views
1 answer 107 views
1 answer 99 views
...