-
-
Save hora/9e572bb5eaaaad729966 to your computer and use it in GitHub Desktop.
W1D2 - Debugging Incorrect Code
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
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