Detect a Palindrome

function isPalindrome(input)
{
	var len = input.length;

	var isPalindrome = true;

	// iterate through half the length of the string
	for(j = 0; j<len/2; j++)
	{
		if(input[j] != input[len - 1 -j])
		{
			isPalindrome = false;	
			break;
		}
	}

	return isPalindrome;
}
document.writeln(isPalindrome("hello"));
document.writeln(isPalindrome("Anna"));
document.writeln(isPalindrome("deified"));

Leave a Reply

You must be logged in to post a comment.