Skip to content

Instantly share code, notes, and snippets.

@hora
Created October 11, 2015 22:50
Show Gist options
  • Save hora/9e572bb5eaaaad729966 to your computer and use it in GitHub Desktop.
Save hora/9e572bb5eaaaad729966 to your computer and use it in GitHub Desktop.
W1D2 - Debugging Incorrect Code
function isPalindrome(str) {
var noSpaces = str.replace(/\s+/g, '');
var mid = Math.floor(noSpaces.length/2);
var last = noSpaces.length - 1;
for (var i = 0; i < mid; i++) {
if (str[i] !== str[last - i]) return false;
}
}
// Test driver code. These should all log true.
console.log(isPalindrome('P') === true);
console.log(isPalindrome('racecar') === true);
console.log(isPalindrome('a santa at nasa') === true);
console.log(isPalindrome('A Toyota') === true);
console.log(isPalindrome('No lemon no melon') === true);
console.log(isPalindrome('just some random words') === false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment