-
-
Save anonymous/25893d17828335be4dbd to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/akiltipu 's solution for Bonfire: Check for Palindromes
This file contains 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: @akiltipu | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%0A%20%20str%20%3D%20str.toLowerCase().replace(%2F%5B%5CW_%5D%2Fg%2C%20%22%22)%3B%0A%20%20%0A%20%20var%20new_str%20%3D%20str.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%0A%20%20if%20(str%20%3D%3D%3D%20new_str)%7B%0A%09return%20true%3B%0A%20%20%7D%0A%20%20else%7B%0A%09return%20false%3B%0A%7D%0A%20%20%0A%7D%0A%0Apalindrome(%22eye%22)%3B | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function palindrome(str) { | |
str = str.toLowerCase().replace(/[\W_]/g, ""); | |
var new_str = str.split("").reverse().join(""); | |
if (str === new_str){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
palindrome("eye"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment