JSFiddle - React, Tailwind, and code Playground

by plus5keen

HTML

<div data-bind="foreach: tests">
    <pre data-bind="text: $data"></pre>
</div>

JavaScript

// Code Golf GCD Prime Factorization

/*
function f(a,b,i,e){return i?a%i|b%i?(e?i+'^'+e+' ':'')+(i>a?'':f(a,b,i+1,0)):f(a/i,b/i,i,e+1):f(a,b,2,0).trim()}
/*/
function f(a,b,i,e){
    return i // Check for factor.
        ?a%i|b%i // Check for indivisibility.
            ?(
                e // Check for exponent.
                    ?i+'^'+e+' ' // Add the current factor to result string.
                    :'' // Omit the current non-factor.
             )+(
                i>a // Check for termination state.
                    ?'' // Stop recursion.
                    :f(a,b,i+1,0) // Go to the next factor.
            )
            :f(a/i,b/i,i,e+1) // Failed indivisibility check. Increment exponent and divide subject values.
        :f(a,b,2,0) // Add default factor and exponent.
        .trim() // Get rid of one extra space that's usually on the end.
}
//*/

ko.applyBindings({
    tests: [
        f(12, 6),
        f(14, 15),
        f(80, 80),
        f(96,162),
        f(162,96),
        f(162, 18),
        f(196,294),
        f(444, 48)
    ]
});