check for palindrome (v2)

Revision 2 of this benchmark created by joe on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<h1>Palindrome Checker</h1>
                <input type="text" id="textField" placeholder="Enter your word or phrase" value="A man, a plan, a canal, Panama!" style="width:25%"/>
                <input type="button"  id="checkText" value="Is it a Palindrone?" />

Test runner

Ready to run.

Testing in
TestOps/sec
using an array
document.getElementById('checkText').addEventListener('click', function(){
                                var e = document.getElementById('textField').value.replace(/\W/g, '').toLowerCase();
                                var msg = (e == e.split('').reverse().join(''))? 'Palindrome' :'Not!';
                                alert(msg);
                        }, false);

 
ready
using prototype
$('checkText').observe('click', function(){
                                var cleaned = $F('textField').replace(/\W/g,'').toLowerCase().toArray();
                                var msg = (cleaned.toString() == cleaned.reverse().toString())? 'Palindrome! :D': 'No Palindrome :(';
                                        alert(msg);
                        }, false);
                
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.