;(function(){
var PalindromeChecker = function(){
};
PalindromeChecker.prototype = {
check: function(str){
str = str.replace(/\s/g, '').replace(/\W+/g, '').toLowerCase();
reversed = str.split("").reverse().join("");
if(str === reversed){
return true;
} else {
return false;
}
}
};
var checker = new PalindromeChecker();
var test = [
'A but tuba.',
'A car, a man, a maraca.',
'A dog, a plan, a canal: pagoda.',
'A dog! A panic in a pagoda!',
'A lad named E. Mandala',
'A man, a plan, a canal: Panama.',
'A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!',
'A new order began, a more Roman age bred Rowena.',
'A nut for a jar of tuna.',
'A Santa at Nasa.',
'Not a palindrome!'
];
for(var i = 0; i < test.length; i++){
result = checker.check(test[i]);
document.getElementById('results').innerHTML += '<li class="'+result+'">'+test[i]+': '+result+'</li>';
}
})();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.