function palindrome(str) {
// Good luck!
// \W -->匹配所有的字母、数字、下划线以外的字符
str = str.replace(/\W|_/g,'').toLowerCase();
var arrMaxIndex = str.length -1;
for(var i = 0;i <=arrMaxIndex/2;i++){
if(str.charAt(i)!==str.charAt(arrMaxIndex-i)){
return false;
}
}
return true;
}
Created
August 29, 2016 15:33
-
-
Save GeekaholicLin/5649247a03ad8f59f4eb18288d50251b to your computer and use it in GitHub Desktop.
js 去除标点符号/空格且忽略大小写的回文串判定
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
谢谢, 参考了下正则的部分