Entry
How would I write a script to find wheather a word is palindrome
Apr 8th, 2008 19:18
ha mo, Dave Clark, prerna bk,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Prema,
Here's one way at least:
var str = "A man, a plan, a canal, Panama!";
//
var len, str = str.toLowerCase().replace(/[^a-z]/g, '');
var x, half = Math.ceil((len = str.length) / 2);
for (x=0; x<half; ++x)
{
if (str.substr(x,1) != str.substr(len-1-x,1)) break;
}
if (x < half)
alert('String is not a palindrome.');
else
alert('String is a palindrome.');
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com