tables-js

function represent(i) {
    symbs = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    if(i < 36)
        return symbs[i]
    else
        return '[' + i + ']'
};

function show_int_at_base(basen, val) {
    result = ''
    while(true) {
        quot = Math.floor(val / basen)
        rem = val % basen
        val = quot
        result = represent(rem) + result
        if(val == 0)
            break
    }
    return result
}

function show_base(basen, val) {
    result = show_int_at_base(basen, val)
    pad = 2
    if(result.length < pad) {
        return Array(pad-result.length+1).join(' ')+result
    } else {
        return result
    }
}

function row(oper, basen, i) {
    result = '|'
    for(var start=0; start<basen; ++start)
        result += ' ' + show_base(basen, oper(start, i)) + ' |'
    return result
}

function table(oper, basen){
    result = ''
    for(var start=0; start<basen; ++start)
        result += '| ' + show_base(basen, start) + ' ' + row(oper, basen, start) + '\n'
    return result+'\n'
}

function md_table(oper, basen){
    return '|    ' + row(function(x,y){return x*y}, basen, 1) + '\n|'+
        Array(basen+2).join(':--:|')+'\n'+table(oper, basen);
}

BASE = +process.argv[2]

console.log(md_table(function(x,y){return x+y}, BASE))
console.log(md_table(function(x,y){return x*y}, BASE))