Skip to content

Instantly share code, notes, and snippets.

  • Save terdia/c577fb6ce68ccc707bfe to your computer and use it in GitHub Desktop.
Save terdia/c577fb6ce68ccc707bfe to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/terdia 's solution for Bonfire: Check for Palindromes
// Bonfire: Check for Palindromes
// Author: @terdia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%2F%2F%20Good%20luck!%0A%20%20%0A%20%20%2F%2Fgnoring%20punctuation%2C%20case%2C%20and%20spacing%0A%20%20var%20strippedString%20%3D%20str.toLowerCase().replace(%2F%5CW%7C_%2Fg%2C%20%27%27)%3B%0A%20%20%0A%20%20%2F%2Freverse%20the%20string%20entered%20in%20the%20function%20%0A%20%20var%20reverseString%20%3D%20strippedString.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%0A%20%20%2F%2Fcheck%20if%20reverseString%20is%20equal%20to%20strippedString%20then%20return%20true%20%0A%20%20%2F%2Felse%20return%20false%0A%20%20%0A%20%20if(strippedString%20%3D%3D%3D%20reverseString)%7B%0A%20%20%20%20return%20true%3B%0A%20%20%7D%0A%20%20%0A%20%20return%20false%3B%0A%7D%0A%0A%0A%0Apalindrome(%22A%20man%2C%20a%20plan%2C%20a%20canal.%20Panama%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
//gnoring punctuation, case, and spacing
var strippedString = str.toLowerCase().replace(/\W|_/g, '');
//reverse the string entered in the function
var reverseString = strippedString.split("").reverse().join("");
//check if reverseString is equal to strippedString then return true
//else return false
if(strippedString === reverseString){
return true;
}
return false;
}
palindrome("A man, a plan, a canal. Panama");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment