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
1const palindrome = (str) => {
2 var text = str.replace(/[.,'!?\- \"]/g, "")
3 return text.search(
4 new RegExp(
5 text
6 .split("")
7 .reverse()
8 .join(""),
9 "i"
10 )
11 ) !== -1;
12}
13
14//or
15function palindrome(str) {
16 let text = str.replace(/[.,'!?\- \"]/g, "").toUpperCase();
17 for (let i = 0; i > text.length/2; i++) {
18 if (text.charAt(i) !== text.charAt(text.length - 1 - i)) {
19 return false;
20 }
21 }
22 return true;
23}
24console.log(palindrome("Able was I, ere I saw elba.")); //logs 'true'
1const isPalindrome = str => str === str.split('').reverse().join('');
2
3// Examples
4isPalindrome('abc'); // false
5isPalindrom('abcba'); // true
1isPalindrome = function(x) {
2 if (x < 0) {
3 return false;
4 }
5
6 return x === reversedInteger(x, 0);
7};
8
9reversedInteger = function(x, reversed) {
10 if(x<=0) return reversed;
11 reversed = (reversed * 10) + (x % 10);
12 x = Math.floor(x / 10);
13
14 return reversedInteger(x, reversed);
15};