Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Palindromes and regexp...hooray!
function palindrome(str) {
// Good luck!
var re = /[\s\!\@\#\$\%\^\&\*\(\)\+\=\-/\\\\:\_]/g,
cleanStr,
revStr;
cleanStr = str.toLowerCase().replace(re, "");
revStr = cleanStr.split("").reverse().join("");
if (cleanStr === revStr) {
return true;
} else { console.log(cleanStr); }
}
palindrome("0_0 (: /-\ :) 0-0");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment