-
-
Save potatowave/9f07c70d75cb2d743b81d0ca72150627 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) { | |
str = str.split(" ").join("").toLowerCase(); | |
var mid = Math.floor(str.length / 2); | |
var last = str.length - 1; | |
for (var i = 0; i <= mid; i++) { | |
// console.log(">>>>" + str[i] + " " + str[last - i]); | |
if (str[i] !== str[last - i]) { | |
return false; | |
} | |
} | |
return true;//never found unequal chars | |
} | |
// Test driver code. These should all log true. | |
console.log(isPalindrome('p') === true); | |
console.log(isPalindrome('foo') === false); | |
console.log(isPalindrome('racecar') === true); | |
console.log(isPalindrome('Kayak') === true); | |
console.log(isPalindrome('a santa at NASA') === true); | |
console.log(isPalindrome('live without evil') === false); | |
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