Multiplication tables: Difference between revisions
m
→Functional (ES5)
Line 2,040:
<lang JavaScript>(function (m, n) {
// [m..n]
function range(m, n) {
Line 2,047:
});
}
// Monadic bind (chain) for lists
function
return [].concat.apply([], xs.map(f));
}
var
lstTable = [['x'].concat(
return
/* FORMATTING OUTPUT */
// [[a]] -> bool -> s -> s
function wikiTable(lstRows, blnHeaderRow, strStyle) {
Line 2,074 ⟶ 2,071:
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
Line 2,080 ⟶ 2,077:
}).join('') + '\n|}';
}
// Formatted as WikiTable
return wikiTable(
Line 2,086 ⟶ 2,083:
'text-align:center;width:33em;height:33em;table-layout:fixed;'
) + '\n\n' +
// or simply stringified as JSON
JSON.stringify(lstTable);
})(1, 12);</lang>
|