Skip to content

Instantly share code, notes, and snippets.

@mijimoco
Last active January 10, 2017 08:14
Show Gist options
  • Save mijimoco/9304f92d23ec24dc2c94258a827bcc48 to your computer and use it in GitHub Desktop.
Save mijimoco/9304f92d23ec24dc2c94258a827bcc48 to your computer and use it in GitHub Desktop.
Check for Palindromes Challenge
// This is the function we wrote in another challenge
function reverseString(str) {
var revStr = str.split('').reverse().join('');
return revStr ;
}
// This one is the new function
function palindrome(str) {
// Good luck!
var newStr = str.replace(/\W/g, '').replace(/-/g, '').replace(/_/g, '').toLowerCase();
if(newStr === reverseString(newStr)) {
console.log(newStr + ' true');
return true;
} else console.log(newStr + ' false');
return false;
//console.log(newStr);
}
palindrome("_eye");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment