HTML5, CSS3 & JS Experiments

By Martin Ivanov

Palindrome Checker

Demo

Open your browser's console and reload the page.

Register the Class

<script src="AcidJs.Palindrome/classes/Palindrome.js"></script>

Usage and Code Insight

(function() {
            
    "use strict";

    var
        palindrome = new window.AcidJs.Palindrome();

    console.log("Bob", palindrome.compare("Bob")); // true
    console.log("Nenonen", palindrome.compare("Nenonen")); // true
    console.log("Otto", palindrome.compare("Otto")); // true

    console.log("Martin", palindrome.compare("Martin")); // false
    console.log("JavaScript", palindrome.compare("JavaScript")); // false
})();
/*
 * Palindrome (JavaScript palindrome checker)
 * @namespace window.AcidJs
 * @class Palindrome
 * @version 1.0
 * @developer Martin Ivanov
 * @url developer website: http://wemakesites.net/
 * @url developer twitter: https://twitter.com/#!/wemakesitesnet
 * @url developer blog http://acidmartin.wordpress.com/
 **/

(function() {
    "use strict";
    
    /*
     * @namespace window.AcidJs
     **/
    if(undefined === window.AcidJs) {
        window.AcidJs = {};
    }
    
    /*
     * @namespace window.AcidJs
     * @class Palindrome
     * @constructor
     * @return {Object}
     **/
    function Palindrome() {
        
    }
    
    /*
     * @class Palindrome
     * @prototype Palindrome 
     **/
    Palindrome.prototype = {
        
        /*
         * Check if a string is a palindrome
         * @method compare
         * @param word {String}
         * @public
         * @return Boolean
         **/
        compare: function(word) {
            if(!word || "string" !== typeof(word) || word.toLowerCase() !== word.split("").reverse().join("").toLowerCase()) {
                return false;
            }
            return true;
        }
    };
    
    /*
     * Add to the window.AcidJs namespace 
     **/
    window.AcidJs.Palindrome = Palindrome;
})();

Please, disable your ad blocker

This website is made possible by displaying online advertisements to the visitors. To view the content, please, disable your ad blocker, then refresh the page.