Created
March 2, 2017 06:20
-
-
Save urcades/cf676a7348a553a27f64649ef52d1755 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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