Skip to content

Commit 2b83b82

Browse files
committed
Reto 15
1 parent 2233d5d commit 2b83b82

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| <img src="./Assets/Retos_SVG/12.svg" width="80" height="80" /> | #12 | [Trineos eléctricos, ¡guau!](https://adventjs.dev/es/challenges/2022/12) | [Ver](./Reto_12/README.md) | Medio | [Ver](./Reto_12/index.js) | 280 |
2323
| <img src="./Assets/Retos_SVG/13.svg" width="80" height="80" /> | #13 | [Backup de los archivos de Papá Noel](https://adventjs.dev/es/challenges/2022/13) | [Ver](./Reto_13/README.md) | Fácil | [Ver](./Reto_13/index.js) | 260 |
2424
| <img src="./Assets/Retos_SVG/14.svg" width="80" height="80" /> | #14 | [El mejor camino](https://adventjs.dev/es/challenges/2022/14) | [Ver](./Reto_14/README.md) | Medio | [Ver](./Reto_14/index.js) | 300 |
25-
| <img src="./Assets/Retos_SVG/15.svg" width="80" height="80" /> | #15 | [Decorando el árbol de Navidad](https://adventjs.dev/es/challenges/2022/15) | [Ver](./Reto_15/README.md) | Medio | [Ver](./Reto_15/index.js) | ? |
25+
| <img src="./Assets/Retos_SVG/15.svg" width="80" height="80" /> | #15 | [Decorando el árbol de Navidad](https://adventjs.dev/es/challenges/2022/15) | [Ver](./Reto_15/README.md) | Medio | [Ver](./Reto_15/index.js) | 10 |
2626
| <img src="./Assets/Retos_SVG/16.svg" width="80" height="80" /> | #16 | [Arreglando las cartas de Papá Noel](https://adventjs.dev/es/challenges/2022/16) | [Ver](./Reto_16/README.md) | Difícil | [Ver](./Reto_16/index.js) | ? |
2727
| <img src="./Assets/Retos_SVG/17.svg" width="80" height="80" /> | #17 | [Llevando los regalos en sacos](https://adventjs.dev/es/challenges/2022/17) | [Ver](./Reto_17/README.md) | Medio | [Ver](./Reto_17/index.js) | ? |
2828
| <img src="./Assets/Retos_SVG/18.svg" width="80" height="80" /> | #18 | [¡Nos quedamos sin tinta!](https://adventjs.dev/es/challenges/2022/18) | [Ver](./Reto_18/README.md) | Fácil | [Ver](./Reto_18/index.js) | 80 |

Reto_15/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,57 @@ decorateTree('B B'); // ['B', 'B B']
4545
- El programa recibe siempre la cadena de texto que representa la base del árbol.
4646
- Hay que generar el árbol completo, es decir, la base y las filas que se generan a partir de ella, hasta arriba.
4747
- Hay que seguir la fórmula para saber qué decoración colocar en cada posición.
48+
49+
---
50+
51+
## Resultados
52+
53+
### Test #01
54+
55+
```js
56+
Test: return type;
57+
58+
Expected: 'array';
59+
60+
Actual: 'array';
61+
```
62+
63+
### Test #02
64+
65+
```js
66+
Test: decorateTree('B P R P');
67+
68+
Expected: ['R', 'P B', 'R B B', 'B P R P'];
69+
70+
Actual: ['R', 'P B', 'R B B', 'B P R P'];
71+
```
72+
73+
### Test #03
74+
75+
```js
76+
Test: decorateTree('B B');
77+
78+
Expected: ['B', 'B B'];
79+
80+
Actual: ['B', 'B B'];
81+
```
82+
83+
### Test #04
84+
85+
```js
86+
Test: decorateTree('B B P R P R R');
87+
88+
Expected: ['B', 'R P', 'B P P', 'P R B R', 'P P B B P', 'B R B B B R', 'B B P R P R R'];
89+
90+
Actual: ['B', 'R P', 'B P P', 'P R B R', 'P P B B P', 'B R B B B R', 'B B P R P R R'];
91+
```
92+
93+
### Test #05
94+
95+
```js
96+
Test: decorateTree('R R P R R');
97+
98+
Expected: ['R', 'R R', 'P B P', 'R B B R', 'R R P R R'];
99+
100+
Actual: ['R', 'R R', 'P B P', 'R B B R', 'R R P R R'];
101+
```

Reto_15/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function decorateTree(base) {
2+
let combs = {
3+
PP: 'P',
4+
BB: 'B',
5+
RR: 'R',
6+
BP: 'R',
7+
PB: 'R',
8+
RP: 'B',
9+
PR: 'B',
10+
BR: 'P',
11+
RB: 'P',
12+
};
13+
14+
let nextLevel = '';
15+
let current = '';
16+
let final = [];
17+
18+
let remainLvl = base.split(' ').length - 1;
19+
20+
final.push(base);
21+
while (remainLvl > 0) {
22+
let newString = '';
23+
for (let i = 0; i < base.length - 1; i += 2) {
24+
current = base[i] + base[i + 2];
25+
26+
if (base[i + 2]) {
27+
nextLevel = combs[current];
28+
newString += nextLevel + ' ';
29+
}
30+
}
31+
base = [...newString];
32+
final.push(newString.trim());
33+
remainLvl--;
34+
}
35+
36+
return final.reverse();
37+
}

0 commit comments

Comments
 (0)