Skip to content

Commit 366fd4c

Browse files
committed
2024 - 06
1 parent 54cd6ae commit 366fd4c

File tree

7 files changed

+311
-199
lines changed

7 files changed

+311
-199
lines changed

2024/01.md

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function prepareGifts(gifts) {
3939

4040
> Puntaje: 🌟🌟🌟🌟🌟
4141
42+
> 2317 ops/s
43+
44+
> Complejidad cognitiva: 2
45+
4246
<br/>
4347

4448
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

2024/02.md

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function createFrame (names) {
6161

6262
> Puntaje: 🌟🌟🌟🌟🌟
6363
64+
> 2345 ops/s
65+
66+
> Complejidad cognitiva: 3
67+
6468
<br/>
6569

6670
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

2024/03.md

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ function organizeInventory(inventory) {
8383
8484
> Puntaje: 🌟🌟🌟🌟🌟
8585
86+
> 1573 ops/s
87+
88+
> Complejidad cognitiva: 1
89+
8690
<br/>
8791
8892
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

2024/04.md

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function createXmasTree(height, ornament) {
7878

7979
> Puntaje: 🌟🌟🌟🌟🌟
8080
81+
> 1887 ops/s
82+
83+
> Complejidad cognitiva: 3
84+
8185
<br/>
8286

8387
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

2024/05.md

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function organizeShoes(shoes) {
7070

7171
> Puntaje: 🌟🌟🌟🌟🌟
7272
73+
> 1543 ops/s
74+
75+
> Complejidad cognitiva: 4
76+
7377
<br/>
7478

7579
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

2024/06.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[⬅️ Regresar](https://github.com/cosmoart/adventJS)
2+
3+
# Reto #6: 📦 ¿Regalo dentro de la caja?
4+
5+
<details>
6+
<summary>Instrucciones</summary>
7+
8+
</br>
9+
10+
Ya hemos empaquetado cientos de regalos 🎁… pero a un elfo se le ha olvidado revisar si el regalo, representado por un asterisco *, está dentro de la caja.
11+
12+
La caja tiene un regalo (*) y cuenta como dentro de la caja si:
13+
14+
- Está rodeada por # en los bordes de la caja.
15+
- El * no está en los bordes de la caja.
16+
17+
Ten en cuenta entonces que el * puede estar dentro, fuera o incluso no estar. Y debemos devolver true si el * está dentro de la caja y false en caso contrario.
18+
19+
Ejemplos:
20+
21+
```js
22+
inBox([
23+
"###",
24+
"#*#",
25+
"###"
26+
]) // ➞ true
27+
28+
inBox([
29+
"####",
30+
"#* #",
31+
"# #",
32+
"####"
33+
]) // ➞ true
34+
35+
inBox([
36+
"#####",
37+
"# #",
38+
"# #*",
39+
"#####"
40+
]) // ➞ false
41+
42+
inBox([
43+
"#####",
44+
"# #",
45+
"# #",
46+
"# #",
47+
"#####"
48+
]) // ➞ false
49+
```
50+
</details>
51+
52+
<br/>
53+
54+
## Solución
55+
56+
```js
57+
function inBox(box) {
58+
const y = box.findIndex(b => b.includes("*"))
59+
const x = box[y]?.indexOf("*")
60+
61+
const positions = [
62+
box[y - 1]?.[x],
63+
box[y]?.[x + 1],
64+
box[y + 1]?.[x],
65+
box[y]?.[x - 1]
66+
]
67+
68+
return positions.every(pos => pos)
69+
}
70+
```
71+
72+
> Puntaje: 🌟🌟🌟🌟🌟
73+
74+
> 2114 ops/s
75+
76+
> Complejidad cognitiva: 3
77+
78+
<br/>
79+
80+
[⬅️ Regresar](https://github.com/cosmoart/adventJS)

0 commit comments

Comments
 (0)