forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
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 mouredev#3467 from marcode24/challenge-20
Reto mouredev#20 - Javascript
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Retos/Reto #20 - LA TRIFUERZA [Media]/javascript/marcode24.js
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,32 @@ | ||
/* | ||
* ¡El nuevo "The Legend of Zelda: Tears of the Kingdom" ya está disponible! | ||
* | ||
* Crea un programa que dibuje una Trifuerza de "Zelda" | ||
* formada por asteriscos. | ||
* - Debes indicarle el número de filas de los triángulos con un entero positivo (n). | ||
* - Cada triángulo calculará su fila mayor utilizando la fórmula 2n-1. | ||
* | ||
* Ejemplo: Trifuerza 2 | ||
* | ||
* * | ||
* *** | ||
* * * | ||
* *** *** | ||
* | ||
*/ | ||
|
||
const buildTreeForce = (n) => { | ||
let tree = ''; | ||
const width = 2 * n - 1; | ||
for (let i = 1; i <= n; i++) { | ||
const upSpaces = ' '.repeat(width + 2 - i * 2); | ||
const upAsterisks = `${upSpaces}${'* '.repeat(i - 1)}*${upSpaces}`; | ||
const downSpaces = ' '.repeat(2 * n - i * 2); | ||
const downAsterisks = `${`${'*'.repeat(3)} `.repeat(i - 1)}${'*'.repeat(3)}`; | ||
const downAsterisksCompleted = downSpaces + downAsterisks + downSpaces; | ||
tree += `${upAsterisks}\n${downAsterisksCompleted}\n`; | ||
} | ||
return tree.slice(0, -1); | ||
}; | ||
|
||
// Visita mi repo en GitHub para ver y correr los tests de este código --> https://github.com/marcode24/weekly-challenges |