-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2.js
32 lines (27 loc) · 789 Bytes
/
p2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* Implement a function `isPalindrome` which takes a string as argument and returns true/false as its result.
Note: the input string is case-insensitive which means 'Nan' is a palindrom as 'N' and 'n' are considered case-insensitive. */
function isPalindrome(str){
str=str.toLowerCase();
strArr=str.split(' ').join('');
let len=strArr.length;
let j=0;
if(len % 2===0){
let pt=len/2;
if(strArr[pt]===str[pt-1]){
console.log('Plaindrome')
}
}
else{
for(i=0;i<len-1;i++){
if(strArr[i]!=strArr[len-1-i]){
j++;
}
}
if(j>0){
console.log('Not Palindrome')
}
else
console.log('Palindrome')
}
}
isPalindrome('Race car')