Created
October 4, 2017 07:19
-
-
Save dre4success/8691aa71b14afd28c8854e622b65c469 to your computer and use it in GitHub Desktop.
To return true or false if a statement is palindrome, i.e same when spelt backward
This file contains 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 isPalindrome(str) { | |
// convert string to lowercase | |
str = str.toLowerCase(); | |
// convert string to an array | |
let strArr = str.split(''); | |
// what it will be checked against to eliminitate non alphabetic characters | |
let AlphabetArr = 'abcdefghijklmnopqrstuvwxyz'.split(''); | |
// initialize an empty array | |
let newContainer = [] | |
strArr.forEach(char => { | |
if(AlphabetArr.indexOf(char) > -1) { | |
newContainer.push(char) | |
} | |
}) | |
if(newContainer.join('') === newContainer.reverse().join('')) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment