Forked from anonymous/bonfire-check-for-palindromes.js
Last active
December 11, 2015 02:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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