Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jiyoon-koo/233974eb3bd50b22df6a to your computer and use it in GitHub Desktop.
Save jiyoon-koo/233974eb3bd50b22df6a to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/thetinybeaker 's solution for Bonfire: Check for Palindromes
// Bonfire: Check for Palindromes
// Author: @thetinybeaker
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
//turn original string to lowercase, then eliminate any non-alphanumeric values and spaces.
var initString = str.toLowerCase().replace(/[\W_]/g,'');
//take that 'normalized' string and split and reverse.
var revString = initString.split('').reverse().join('');
// very simple if else statement. if initString is equal to revString, it is a palindrome. else, it is not a palindrome.
if (initString === revString) {
return true;
}
else {
return false;
}
}
palindrome("0_0 (: /-\ :) 0-0");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment