Skip to content

Instantly share code, notes, and snippets.

@Joejhorn
Last active January 12, 2018 06:44
Show Gist options
  • Select an option

  • Save Joejhorn/200cf983c942c37f1dc2591d828722b4 to your computer and use it in GitHub Desktop.

Select an option

Save Joejhorn/200cf983c942c37f1dc2591d828722b4 to your computer and use it in GitHub Desktop.
Palindromes - freecodecamp algorithm challenge
function palindrome(str) {
console.log(str);
var strLowerStripped = str.toLowerCase().replace(/[^a-zA-Z0-9]+/g,'');
//split the string into an array
var splitString = strLowerStripped.split("");
//reverse the string
splitString.reverse();
//join the arry back together
var joinArray = splitString.join("");
console.log(joinArray);
console.log(strLowerStripped);
if (joinArray === strLowerStripped){
return true;
}
return false;
}
palindrome("1 eye for of 1 eye.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment