javascript判断字符串是否是回文的算法实现

var str = "reaaer",
	    len = str.length,
		e=(!!(len%2)),
	    mid = e?Math.floor(len/2):(len/2),
	    prev = str.substring(0,mid),
	    next = e?str.substring(mid+1):str.substring(mid),
	    reg = new RegExp("["+prev+"]","g");
		
	//alert(next.match(reg).length === prev.length);
	alert(next.split("").reverse().join("")===prev);

 你还有更好的算法吗?

相关推荐