JSFiddle - React, Tailwind, and code Playground

by ktstowell

HTML

<h1><a href="http://projecteuler.net/problem=4">Problem:</a></h1>
<p>
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
</p>

<p>Find the largest palindrome made from the product of two 3-digit numbers.</p>
<hr />
<div id="pal"></div>

JavaScript

(function(doc){
    var ceil = 999,
        floor = 99,
        c1 = ceil,
        c2,
        prd,
        //inner,
        stamp = new Date();

    (function outer() {
        if(c1 > floor) {
            c2 = ceil;
            (function inner() {
                if(c2>floor) {
                    prd = c1*c2;
                    if(isPalindrome(prd)) {
                        console.log(c1, c2, prd);
                    } else {
                        c2--;
                        setTimeout(inner,1);
                    }
                } else {
                    c1--;
                    outer();
                }
            })();
        } else {
            console.log(stamp.getMinutes());
            console.log('DONE');
        }
    })();
    
    function isPalindrome(n) {
        var i,
            arr = [];
        
        n = n.toString();
        
        for(i=0;i<n.length;i++) {
            (n[i] !== n[(n.length-1) - i])
                ? arr.push('false')
                    : arr.push('true');
                
        }
        
        if (arr.indexOf('false') !== -1) {
            return false;
        } else {
            return true;
        }
        
        arr.length = 0;
    }
})(document);