Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piqueen314/a18ade844725d1261656 to your computer and use it in GitHub Desktop.
Save piqueen314/a18ade844725d1261656 to your computer and use it in GitHub Desktop.
Return true if the given string is a palindrome. Otherwise, return false.
// Bonfire: Check for Palindromes
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
str=str.toLowerCase();
str=str.replace(/\W/g,"").replace(/[_]/g,"");
if(str == str.split('').reverse().join(''))
{
return true;
}
return false;
}
palindrome("not a palindrome");
// Bonfire: Check for Palindromes
// Author: @piqueen314
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
str=str.toLowerCase();
str=str.replace(/\W/g,"").replace(/[_]/g,"");
if(str == str.split('').reverse().join(''))
{
return true;
}
return false;
}
palindrome("not a palindrome");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment