Skip to main content
2 of 3
Dropped the function
steenbergh
  • 8.1k
  • 1
  • 25
  • 41

Javascript, 194 bytes

Late to the party, but I was piqued by @jdstankosky 's comment and decided to take a different approach. Here's a Javascript entry that mauls a template and evals itself along the way.

t="a*b=c ";u="";r=u;for(i=1;i<10;i++){a=0;u=u+t;v=u.split(' ');r+=v.map(x=>x.replace('a',++a).replace('b',i)).map(x=>x.replace('*','x').replace('c',eval(x.substr(0,3)))).join(' ')+'\n'}alert(r);

Un-golfed version (slightly older version in which a function returns the table instead of a script alerting it, but the same principles apply):

function f()
{
    t="a*b=c "; // template for our multiplication table
    u="";r="";  // tmp- and return values
    for(i=1;i<10;i++)
    {
        a=0;    // is auto-incremented in MAP
        u=u+t;// extend the template once per iteration
        v=u.split(' '); // Smash the template to pieces
        w=v.map(x=>x.replace('a', ++a).replace('b', i)) // MAP replaces the A and B's with the correct numbers
        w=w.map(x=>x.replace('*', 'x').replace('c', eval(x.substring(0,3)))).join(' '); // second map evals that and replaces c with the answer, makes the asteriks into an X
        r=r+w+'\n'  // results get concatenated
    }
    return r;
}
steenbergh
  • 8.1k
  • 1
  • 25
  • 41