Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
var palindrome = "a man a plan a canal panama"; function detectPalindrome(inThisString){ // first we remove all the white space, because we're going on the premise that it's // non significant var testString = inThisString.replace(/\W/g, ""); // then we just compare the letter at a given offset from the front to the letter of // the same offset from the back, any difference no palindrome for (var x=0;x< testString.length;x++){ if (testString[x] != testString[testString.length - (x + 1)]){ return false; } } return true; } var palindromeIsPalindrome = detectPalindrome(palindrome); var nonPalindromeIsPalindrome = detectPalindrome("rooster"); alert("Palindrome: " + palindromeIsPalindrome + "\nNon: " + nonPalindromeIsPalindrome);