Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattnwa/a3d9105d82c892d5d216 to your computer and use it in GitHub Desktop.
Save mattnwa/a3d9105d82c892d5d216 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mattnwa 's solution for Bonfire: Check for Palindromes
// 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