Skip to content

Instantly share code, notes, and snippets.

@dre4success
Created October 4, 2017 07:19
Show Gist options
  • Save dre4success/8691aa71b14afd28c8854e622b65c469 to your computer and use it in GitHub Desktop.
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
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