Task

Produce a formatted   12×12   multiplication table of the kind memorized by rote when in primary (or elementary) school.



Only print the top half triangle of products.




 
// Multiplication tables
 
function intToString(n: number, wdth: number): string {
  sn = Math.floor(n).toString();
  len = sn.length;
  return (wdth < len ? "#".repeat(wdth) : " ".repeat(wdth - len) + sn);
}
 
var n = 12;
console.clear();
for (j = 1; j < n; j++)
  process.stdout.write(intToString(j, 3) + " ");
console.log(intToString(n, 3));
console.log("----".repeat(n) + "+");
for (i = 1; i <= n; i++) {
  for (j = 1; j <= n; j++)
    process.stdout.write(j < i ? "    " : intToString(i * j, 3) + " ");
  console.log("| " + intToString(i, 2));
}
 