Skip to content

Instantly share code, notes, and snippets.

@urcades
Created March 2, 2017 06:20
Show Gist options
  • Save urcades/cf676a7348a553a27f64649ef52d1755 to your computer and use it in GitHub Desktop.
Save urcades/cf676a7348a553a27f64649ef52d1755 to your computer and use it in GitHub Desktop.
function palindrome(str) {
// make string lowercase
str.toLowerCase();
// eliminate all weird characters
str.replace(/\W,_/gi, '');
// I need to turn the 'str' variable into an array and reverse it
// turning it/assigning it into a new array, reverseStr
var reverseStr = str.split('').reverse().join('');
// I then need to compare the two arrays
// to see if they are equal, if they are, then it's a palindrome.
if (str === reverseStr) {
return true;
} else {
return false;
}
}
palindrome("_eye");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment