配列をテーブルにする

TH要素はあきらめよう。

var createTableFromArray =
  function (insertTR) {
    return function (ary) {
      var table = document.createElement ('tbody');
      ary.forEach (insertTR, table);
      return table;
    };
  }(function (insertTD) {
     return function (record) {
       record.forEach (insertTD, this.insertRow (-1));
     };
    }(function (text) {
       this.insertCell (-1).textContent = text;
      }));

document.body.appendChild (createTableFromArray ([[1,2,3],[2,3,1],[3,1,2]]));

JavaScript 1.8

const createTableFromArray =
  (function (insertTR)
    (function (ary)
      ary.reduce (insertTR, document.createElement ('table'))))
  
  ((function (insertTD)
     (function (table, record)
      (record.forEach (insertTD, table.insertRow (-1)), table)))
  
   (function (text)
     this.insertCell (-1).textContent = text));