How to check if string is palindrome in TypeScript

2 Answers

0 votes
function ReverseString(s: string) {
    return s.split('').reverse().join('');
}
 
const s = "abcba";
  
const rev = ReverseString(s);
  
if (s == rev)
    console.log("Palindrome");
else
    console.log("Not Palindrome");
  
      
 
  
/*
run:  
  
"Palindrome" 
  
*/

 



answered Jul 4, 2024 by avibootz
0 votes
function isPalindrome(str: string) {
	return str === str.split("").reverse().join("");
}

const str = "abcba";

console.log(isPalindrome(str)); 
  
      
 
  
/*
run:  
  
true 
  
*/

 



answered Jul 4, 2024 by avibootz
...