Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|TypeScript}}: Standard functions are applied to format numbers.
(→{{header|TypeScript}}: Added.) |
(→{{header|TypeScript}}: Standard functions are applied to format numbers.) |
||
Line 5,688:
<lang javascript>
// Ethiopian multiplication
function double(a: number): number {
return 2 * a;
}
function halve(a: number): number {
return Math.floor(a / 2);
}
function isEven(a: number): bool {
return a % 2 == 0;
}
function showEthiopianMultiplication(x: number, y: number): void {
var tot = 0;
while (x >= 1) {
process.stdout.write
if (!isEven(x)) {
tot += y;
process.stdout.write
}
console.log();
Line 5,719 ⟶ 5,713:
y = double(y);
}
console.log("=" + " ".repeat(9) +
}
showEthiopianMultiplication(17, 34);
</lang>
|