Multiplication tables: Difference between revisions

m
Line 2,040:
 
<lang JavaScript>(function (m, n) {
 
// [m..n]
function range(m, n) {
Line 2,047:
});
}
 
// Monadic bind (chain) for lists
function chainmb(xs, f) {
return [].concat.apply([], xs.map(f));
}
 
var lstRangerng = range(m, n),
 
lstTable = [['x'].concat(lstRange rng )].concat(
chain .concat(lstRangemb(rng, function (yx) {
return return [[yx].concat(mb(rng, function (y) {
chain(lstRange, function (x) {
return xy < yx ? [''] : [x * y]; // triangle only
})
}))]}));
})
);
 
 
/* 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>
 
9,659

edits