Multiplication tables: Difference between revisions
Content added Content deleted
m (→lint) |
|||
Line 1,930:
=={{header|JavaScript}}==
===Imperative===
<lang html4strict><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
Line 1,987 ⟶ 1,990:
===Functional (ES5)===
<lang JavaScript>//
// n --> n -->
(function
// [m..n]
return Array.apply(▼
▲ return Array.apply(null, Array(n - m + 1)).map(
return m + i;
}
);▼
}▼
}
//
function wikiTable(lstRows, blnHeaderRow, strStyle) {
var css = strStyle ? 'style="' + strStyle + '"' : '';
▲function cell(n, w) {
return '{| class="wikitable" ' + css + lstRows.map(
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|'),
strDbl = strDelim + strDelim;
return typeof v === 'undefined' ? ' ' : v;
▲(function (m, n, colWidth) {
}).join('') + '\n|}';
}
▲ // x 1 2 3 4 5 6 7 8 9 10 11 12
▲ lstTable = [['x'].concat(lstRange)].concat(
▲ lstRange.map(function (iRow, i, lst) {
return [iRow].concat(
// gap to left (triangle of
Array.apply(null,
return x *
▲ lst.slice(i).map(function (x) {
return x * iRow;▼
})▼
▲ );
})
);
})
);
// Formatted as WikiTable
return wikiTable(
lstTable, true,
'text-align:center;width:33em;height:33em;table-layout:fixed;'
)
▲ }).join('\n');
▲})(1, 12, 5);
Output:
{| class="wikitable" style="text-align:center;width:33em;height:33em;table-layout:fixed;"
|-
1 1 2 3 4 5 6 7 8 9 10 11 12▼
! x !! 1 !! 2 !! 3
|-
| 1 || 1
|-
| 2 ||
|-
7 49 56 63 70 77 84▼
| 3 ||
|-
9 81 90 99 108▼
| 4 ||
|-
11 121 132▼
| 5 ||
|-
| 6 || || || || || || 36 || 42 || 48 || 54 || 60 || 66 || 72
|-
|-
|-
|-
| 10 || || || || || || || || || || 100 || 110 || 120
|-
|-
▲|}
=={{header|Julia}}==
|