Forked from anonymous/bonfire-check-for-palindromes.js
Last active
December 3, 2015 04:58
-
-
Save mattnwa/a3d9105d82c892d5d216 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mattnwa '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: @mattnwa | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
//Steps to think through.. | |
// 1. we need to remove unneeded whitespace/numbers and whitespace. Needs to be lower case. | |
// 2. Need to then create another variable with the string turned into an array and reverse joined. | |
// 3. Compare the two created strings to see if they match. return F/A statement. | |
function palindrome(str) { | |
// Good luck! | |
var replaceAndLower =str.replace(/[^A-Z0-9]/ig, "").toLowerCase(); | |
var reversedStr = replaceAndLower.split('').reverse().join(''); | |
if (reversedStr === replaceAndLower) { | |
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