Skip to content

Instantly share code, notes, and snippets.

@piqueen314 piqueen314/gist2
Created Dec 11, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.