1function palindrome(str) {
2
3 var len = str.length;
4 var mid = Math.floor(len/2);
5
6 for ( var i = 0; i < mid; i++ ) {
7 if (str[i] !== str[len - 1 - i]) {
8 return false;
9 }
10 }
11
12 return true;
13}
14
1function palindrome(str) {
2 var re = /[\W_]/g;
3 var lowRegStr = str.toLowerCase().replace(re, '');
4 var reverseStr = lowRegStr.split('').reverse().join('');
5 return reverseStr === lowRegStr;
6}
7palindrome("A man, a plan, a canal. Panama");
1function palindrome(str) {
2 var re = /[^A-Za-z0-9]/g;
3 str = str.toLowerCase().replace(re, '');
4 var len = str.length;
5 for (var i = 0; i < len/2; i++) {
6 if (str[i] !== str[len - 1 - i]) {
7 return false;
8 }
9 }
10 return true;
11}
12palindrome("A man, a plan, a canal. Panama");
1const isPalindrome = str => str === str.split('').reverse().join('');
2
3// Examples
4isPalindrome('abc'); // false
5isPalindrom('abcba'); // true
1function palindrome(str) {
2 var splitted = str.split("");
3 var reversed = splitted.reverse("");
4 var joined = reversed.join("");
5 return joined.toLowerCase().replace(/[^0-9a-z]/gi, '') == str.toLowerCase().replace(/[^0-9a-z]/gi, '')
6}
7
1function remove_spaces_strict(string)
2{
3 return string.replace(/\s/gm, "");
4}
5
6function to_lower_case(string="")
7{
8 return string.toLocaleLowerCase();
9}
10
11
12function isPalindrome(string) {
13 let string1 = string;
14 if (typeof string === 'string' || typeof string === 'number') {
15 if (typeof string === 'number') {
16 string1 = new Number(string1).toString();
17 }
18 string1 = remove_spaces_strict(string1);
19 string1 = to_lower_case(string1);
20 let len1 = string1.length;
21 let len = Math.floor(string1.length / 2);
22 let i = 0;
23
24 while(i < len) {
25
26 if (string1[i] !== string1[len1 - (1 + i)]) {
27 return false;
28 }
29 console.log(string1[i] + " = " + string1[len1 - (1 + i)]);
30 i++;
31 }
32 }else{
33 throw TypeError(`Was expecting an argument of type string1 or number, recieved an argument of type ${ typeof string1}`);
34 }
35 return string;
36}
37