1function isPalindrome(sometext) {
2 var replace = /[.,'!?\- \"]/g; //regex for what chars to ignore when determining if palindrome
3 var text = sometext.replace(replace, '').toUpperCase(); //remove toUpperCase() for case-sensitive
4 for (var i = 0; i < Math.floor(text.length/2) - 1; i++) {
5 if(text.charAt(i) == text.charAt(text.length - 1 - i)) {
6 continue;
7 } else {
8 return false;
9 }
10 }
11 return true;
12}
13//EDIT: found this on https://medium.com/@jeanpan/javascript-splice-slice-split-745b1c1c05d2
14//, it is much more elegant:
15function isPalindrome(str) {
16 return str === str.split('').reverse().join('');
17}
18//you can still add the regex and toUpperCase() if you don't want case sensitive
1// devuelve cierto si la subcadena que hay entre las posiciones inicio y fin es palindromo.
2 bool esPalindromo(char cad[], int inicio, int fin){
3 bool pal = false;
4
5 if(inicio == fin){
6 pal = true;
7 }else{
8 if(cad[inicio] == cad[fin]){
9 pal = esPalindromo(cad, inicio + 1, fin - 1);
10 }
11 }
12
13 return pal;
14 }
1//made by Kashish Vaid the great.
2// Palindrome programme using for loop the easiest prgm
3#include <stdio.h>
4int main() {
5 int n, rev = 0, remainder, num;
6 printf("Enter an integer: ");
7 scanf("%d", &n);
8 num = n;
9
10 // reversed integer is stored in rev
11 for(num = n ; n!=0 ; n/=10)
12{
13 remainder = n%10;
14 rev = rev*10 + remainder;
15}
16// if else shortcuts
17 ( (rev == num) ? printf("%d is a palindrome.", num) : printf("%d is not a palindrome.", num) );
18 return 0;
19}
20//made by Kashish Vaid the great.
1#include<iostream>
2#include<string>
3#include<algorithm>
4bool IsPalindrome_true_false(const std::string& );
5
6int main ()
7{
8
9 std::cout<<"Please enter a string:\t";
10 std::string str;
11 getline(std::cin, str);
12
13 // convert the string from uppercase to lowercase
14 int i = 0;
15 while(str[i])
16 {
17 if(str[i] == std::toupper(str[i]) && std::isalpha(str[i]) == 1024)
18 str[i]+= 32;
19 ++i;
20 }
21 // looping while string is empty
22 while(str.empty())
23 {
24 std::cout<<"\nPlease enter a string your string is empty:\t";
25 if(!str.empty())
26 std::string str;
27 getline(std::cin, str);
28 }
29
30 std::cout<<"\n"<<std::boolalpha<<IsPalindrome_true_false(str)<<std::endl;
31 std::cout<<std::endl;
32
33 return 0;
34}
35
36// check if string is a palindrome and return true or false
37bool IsPalindrome_true_false(const std::string& str)
38{
39
40 int i = 0;
41 int j = str.length() - 1;
42
43 while(i <= j )
44 {
45
46 if(std::isalpha(str[i]) == 0){
47 ++i;
48 continue;
49 }else if(std::isalpha(str[j]) == 0){
50 --j;
51 continue;
52 }
53 if(str[i] != str[j]){
54
55 return false;
56 }
57 ++i;
58 --j;
59 }
60 return true;
61}
62
63
64
65
1function isPalindrome(text) {
2 return [...text].reverse().join('') === text;
3}
4
5isPalindrome = text => {
6 return [...text].reverse().join('') === text;
7}
8
9isPalindrome = text => [...text].reverse().join('') === text;
1#include <stdio.h>
2int main() {
3 int n, reversedN = 0, remainder, originalN;
4 printf("Enter an integer: ");
5 scanf("%d", &n);
6 originalN = n;
7
8 // reversed integer is stored in reversedN
9 while (n != 0) {
10 remainder = n % 10;
11 reversedN = reversedN * 10 + remainder;
12 n /= 10;
13 }
14
15 // palindrome if orignalN and reversedN are equal
16 if (originalN == reversedN)
17 printf("%d is a palindrome.", originalN);
18 else
19 printf("%d is not a palindrome.", originalN);
20
21 return 0;
22}
23
24