constisPalindrome=(str)=>{const preprocessing_regex =/[^a-zA-Z0-9]/g,
processed_string = str.toLowerCase().replace(preprocessing_regex ,""),
integrity_check = processed_string.split("").reverse().join("");if(processed_string === integrity_check)returntrueelsereturnfalse}//if you find this answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
/*
C++ Palindrome Checker program by lolman_ks.
Checks palindromic string WITHOUT reversing it.
Same logic can be used to build this program in other languages.
*//*
Logic: In a palindromic string, the 1st and last, 2nd and 2nd last, and so
on characters are equal.
Return false from the function if any of these matches, i.e (1st and last),
(2nd and 2nd last) are not equal.
*/
#include <iostream>
using namespace std;
bool checkPalindromicString(string text){
int counter_1 =0;//Place one counter at the start.
int counter_2 = text.length()-1;//And the other at the end.//Run a loop till counter_2 is not less that counter_1.while(counter_2 >= counter_1){if(text[counter_1]!= text[counter_2])returnfalse;//Check for match.//Note: Execution of a function is halted as soon as a value is returned.else{++counter_1;//Move the first counter one place ahead.--counter_2;//Move the second character one place back.}}returntrue;/*
Return true if the loop is not broken because of unequal characters and it
runs till the end.
If the loop runs till the condition specified in it, i.e
(counter_2 >= counter1), that means all matches are equal and the string is
palindromic.
*/}//Implementation of the function.
int main(){
cout <<checkPalindromicString("racecar")<< endl;//Outputs 1 (true).
cout <<checkPalindromicString("text")<< endl;//Outputs 0 (False).if(checkPalindromicString("lol")){
cout <<"#lolman_ks";}//Outputs #lolman_ks.return0;}//I hope this would be useful to you all, please promote this answer if it is.//#lolman_ks
const palindrome = str ={
str = str.replace(/[W+|_]/g,'').toLowerCase()const str1 = str.split('').reverse().join('')return str1 === str
}palindrome("My age is 0, 0 si ega ym.");// With love @kouqhar
let data =12421const dataOne = data.toString().split("").reverse().join("");
data = data.toString();
dataOne === data ?console.log("Palindrom"):console.log("Not Palindorm");
#include <stdio.h>
#include <stdbool.h>
bool is_palindrome(int n){
int rev =0, orig = n;while( n !=0){
rev =10*rev +(n %10);
n = n/10;}return orig == rev;}
int main(){printf("Enter a number");
int n =0;if(scanf("%d",&n)!=1){prinf("Bad input
");}else{if(is_palindrome(n))printf("%d is a palindrome", n);elseprinf("%d is not a palindrome", n);}return0;}
// The Setupfunctionpalindrome(str){// Using Regex to remove all the special character, converted all the string to lowercase to ease working with and assign it to a new variable let newStr = str.replace(/[^a-zA-Z0-9]/g,'').toLowerCase();// Split the string, reverse, join then assign it to a new variablelet revStr = newStr.split('').reverse().join('');// return their valuereturn newStr === revStr;}palindrome("A man, a plan, a canal. Panama");
<script>// function that check str is palindrome or notfunctioncheck_palindrome(str){let j = str.length-1;for(let i =0; i < j/2;i++){let x = str[i];//forward characterlet y = str[j-i];//backward characterif( x != y){// return false if string not matchreturnfalse;}}/// return true if string is palindromereturntrue;}//function that print output is string is palindromefunctionis_palindrome(str){// variable that is true if string is palindromelet ans =check_palindrome(str);//condition checking ans is true or notif( ans ==true){console.log("passed string is palindrome ");}else{console.log("passed string not a palindrome");}}// test variablelet test ="racecar";is_palindrome(test);</script>
int main(){
char str1[20], str2[20];
int i, j, len =0, flag =0;
cout <<"Enter the string : ";gets(str1);
len =strlen(str1)-1;for(i = len, j =0; i >=0; i--, j++)
str2[j]= str1[i];if(strcmp(str1, str2))
flag =1;if(flag ==1)
cout << str1 <<" is not a palindrome";else
cout << str1 <<" is a palindrome";return0;}
classSolution:
def isPalindrome(self,string: str ):'''
Afunction to check if a string is Palindrome or not!:param string: string to be checked
:return:Trueif it is palindrome elseFalse'''
string = string.lower()
s_stripped =''.join(list(filter( lambda x : x.isalnum()==True, string)))return s_stripped == s_stripped[::-1]if __name__ =='__main__':
string ='Was it a car or a cat I saw!!'print(f'Is "{string}" a palindrome? : {Solution ().isPalindrome (string)}')
string2 ='A man, a plan,'print(f'Is "{string2}" a palindrome? : {Solution ().isPalindrome (string2)}')
int main(){
char str1[20], str2[20];
int i, j, len =0, flag =0;
cout <<"Enter the string : ";gets(str1);
len =strlen(str1)-1;for(i = len, j =0; i >=0; i--, j++)
str2[j]= str1[i];if(strcmp(str1, str2))
flag =1;if(flag ==1)
cout << str1 <<" is not a palindrome";else
cout << str1 <<" is a palindrome";return0;}
#include <iostream>
#include <deque>
bool is_palindrome(conststd::string &s){if(s.size()==1)returntrue;std::deque<char> d ;for(char i : s){if(std::isalpha(i)){
d.emplace_back(toupper(i));}}
auto front = d.begin();
auto back = d.rbegin();while((front != d.end())||(back != d.rend())){
bool ans =(*front ==*back);if(!ans){return ans;}++front;++back;}returntrue;}
int main(){std::string s ="A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!";std::cout << std::boolalpha <<is_palindrome(s)<< std::endl;return0;}
// can we generate palindrome string by suffling // the character of the string s public bool CanBePalindrome(string s){var dict =newDictionary<char, int>();for(int j =0; j < s.Length; j++){var item = s[j];if(dict.ContainsKey(item)){
dict[item]++;if(dict[item]==2){
dict.Remove(item);}}else{
dict.Add(item,1);}}return dict.Count<=1;}