-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5412 from mxtrar23/main
Reto #40 Typescript
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Retos/Reto #40 - TABLA DE MULTIPLICAR [Fácil]/typescript/mxtrar23.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
/* | ||
* Crea un programa que sea capaz de solicitarte un número y se | ||
* encargue de imprimir su tabla de multiplicar entre el 1 y el 10. | ||
* - Debe visualizarse qué operación se realiza y su resultado. | ||
* Ej: 1 x 1 = 1 | ||
* 1 x 2 = 2 | ||
* 1 x 3 = 3 | ||
* ... | ||
*/ | ||
|
||
interface MultiplicationTable { | ||
multiplicand:number, | ||
multiplier:number, | ||
product:number, | ||
} | ||
|
||
|
||
const doMultiplicationTableByNumber = (multiplicand:number) => { | ||
|
||
const dataTable = multiplicationTable(multiplicand) | ||
printTable(multiplicand,dataTable) | ||
} | ||
|
||
const multiplicationTable = (multiplicand:number) :MultiplicationTable[] => { | ||
const dataTable :MultiplicationTable[] = [] | ||
|
||
for (let index = 1; index <= 10; index++) { | ||
dataTable.push({ | ||
multiplicand, | ||
multiplier : index, | ||
product: (multiplicand*index) | ||
}) | ||
} | ||
|
||
return dataTable | ||
} | ||
|
||
const printTable = (multiplicand:number,dataMultiplicationTable:MultiplicationTable[]) => { | ||
console.log(`==== TABLE OF x${multiplicand} ====`) | ||
dataMultiplicationTable.forEach(row=>{ | ||
const {multiplicand,multiplier,product} = row | ||
console.log(` ${multiplicand} X ${multiplier} = ${product}`); | ||
}) | ||
console.log(`====================`) | ||
|
||
} | ||
|
||
|
||
doMultiplicationTableByNumber(5); | ||
|
||
|
||
/*==== TABLE OF x5 ==== | ||
5 X 1 = 5 | ||
5 X 2 = 10 | ||
5 X 3 = 15 | ||
5 X 4 = 20 | ||
5 X 5 = 25 | ||
5 X 6 = 30 | ||
5 X 7 = 35 | ||
5 X 8 = 40 | ||
5 X 9 = 45 | ||
5 X 10 = 50 | ||
====================*/ |