Multiplication tables: Difference between revisions
Content added Content deleted
(→{{header|TypeScript}}: Added.) |
(→{{header|TypeScript}}: Standard functions have been applied to format numbers.) |
||
Line 6,711: | Line 6,711: | ||
<lang javascript> |
<lang javascript> |
||
// Multiplication tables |
// 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; |
var n = 12; |
||
console.clear(); |
console.clear(); |
||
for (j = 1; j < n; j++) |
for (j = 1; j < n; j++) |
||
process.stdout.write |
process.stdout.write(j.toString().padStart(3, ' ') + " "); |
||
console.log |
console.log(n.toString().padStart(3, ' ')); |
||
console.log("----".repeat(n) + "+"); |
console.log("----".repeat(n) + "+"); |
||
for (i = 1; i <= n; i++) { |
for (i = 1; i <= n; i++) { |
||
for (j = 1; j <= n; j++) |
for (j = 1; j <= n; j++) |
||
process.stdout.write(j < i ? |
process.stdout.write(j < i ? |
||
" " : (i * j).toString().padStart(3, ' ') + " "); |
|||
console.log("| " + |
console.log("| " + i.toString().padStart(2, ' ')); |
||
} |
} |
||
</lang> |
</lang> |