How to check if string is palindrome in Node.js

2 Answers

0 votes
function ReverseString(s) {
    return s.split('').reverse().join('');
}
 
const s = "abccba";
  
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) {
	return str === str.split("").reverse().join("");
}

const str = "abccba";

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

 



answered Jul 4, 2024 by avibootz

Related questions

2 answers 117 views
1 answer 116 views
1 answer 125 views
1 answer 329 views
1 answer 102 views
...