-
-
Save anonymous/95251c05070c697cbfd5 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mike3run '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: @mike3run | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%2F%2F%20Good%20luck!%0A%20%20var%20min%20%3D%20str.toLowerCase().replace(%2F%5Cs%2B%2Fg%2C%20%27%27).replace(%2F%5B.%2C-%5C%2F%23!%24%25%5C%5E%26%5C*%3B%3A%7B%7D%3D%5C-_%60~()%5D%2Fg%2C%22%22)%3B%0A%20%20var%20inv%20%3D%20min.split(%27%27).reverse().join(%27%27)%3B%0A%20%20%0A%20%20if%20(min%20%3D%3D%3D%20inv)%20%7B%0A%20%20%20%20return%20true%3B%0A%20%20%7Delse%20%7B%0A%20%20%20%20return%20false%3B%0A%20%20%7D%0A%7D%0A%0A%0A%0Apalindrome(%22A%20man%2C%20a%20plan%2C%20a%20canal.%20Panama%22)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function palindrome(str) { | |
| // Good luck! | |
| var min = str.toLowerCase().replace(/\s+/g, '').replace(/[.,-\/#!$%\^&\*;:{}=\-_`~()]/g,""); | |
| var inv = min.split('').reverse().join(''); | |
| if (min === inv) { | |
| return true; | |
| }else { | |
| return false; | |
| } | |
| } | |
| palindrome("A man, a plan, a canal. Panama"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment