Skip to content

Commit d18b3db

Browse files
committed
Corrección Roadmap 22 + Nuevo ejercicio 23
1 parent 3aa3a7a commit d18b3db

File tree

3 files changed

+138
-3
lines changed

3 files changed

+138
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
2828
## Corrección y próximo ejercicio
2929

30-
> #### Lunes 3 de junio de 2024 a las 20:00 (hora España) desde **[Twitch](https://twitch.tv/mouredev)**
31-
> #### Consulta el **[horario](https://discord.gg/c2GeX9Kb?event=1242175162275725455)** por país y crea un **[recordatorio](https://discord.gg/c2GeX9Kb?event=1242175162275725455)**
30+
> #### Lunes 10 de junio de 2024 a las 20:00 (hora España) desde **[Twitch](https://twitch.tv/mouredev)**
31+
> #### Consulta el **[horario](https://discord.gg/JP8xRGvR?event=1244742186696970351)** por país y crea un **[recordatorio](https://discord.gg/JP8xRGvR?event=1244742186696970351)**
3232
3333
## Roadmap
3434

@@ -56,7 +56,8 @@
5656
|19|[ENUMERACIONES](./Roadmap/19%20-%20ENUMERACIONES/ejercicio.md)|[📝](./Roadmap/19%20-%20ENUMERACIONES/python/mouredev.py)|[▶️](https://youtu.be/0auuM4GROVA)|[👥](./Roadmap/19%20-%20ENUMERACIONES/)
5757
|20|[PETICIONES HTTP](./Roadmap/20%20-%20PETICIONES%20HTTP/ejercicio.md)|[📝](./Roadmap/20%20-%20PETICIONES%20HTTP/python/mouredev.py)|[▶️](https://youtu.be/-pYMoPYSkgM)|[👥](./Roadmap/20%20-%20PETICIONES%20HTTP/)
5858
|21|[CALLBACKS](./Roadmap/21%20-%20CALLBACKS/ejercicio.md)|[📝](./Roadmap/21%20-%20CALLBACKS/python/mouredev.py)|[▶️](https://youtu.be/tqQo9SjJFlY)|[👥](./Roadmap/21%20-%20CALLBACKS/)
59-
|22|[FUNCIONES DE ORDEN SUPERIOR](./Roadmap/22%20-%20FUNCIONES%20DE%20ORDEN%20SUPERIOR/ejercicio.md)|[🗓️ 03/06/24](https://discord.gg/c2GeX9Kb?event=1242175162275725455)||[👥](./Roadmap/22%20-%20FUNCIONES%20DE%20ORDEN%20SUPERIOR/)
59+
|22|[FUNCIONES DE ORDEN SUPERIOR](./Roadmap/22%20-%20FUNCIONES%20DE%20ORDEN%20SUPERIOR/ejercicio.md)|[📝](./Roadmap/22%20-%20FUNCIONES%20DE%20ORDEN%20SUPERIOR/python/mouredev.py)||[👥](./Roadmap/22%20-%20FUNCIONES%20DE%20ORDEN%20SUPERIOR/)
60+
|23|[SINGLETON](./Roadmap/23%20-%20SINGLETON/ejercicio.md)|[🗓️ 10/06/24](https://discord.gg/JP8xRGvR?event=1244742186696970351)||[👥](./Roadmap/23%20-%20SINGLETON/)
6061

6162
## Instrucciones
6263

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from functools import reduce
2+
from datetime import datetime
3+
4+
"""
5+
Ejercicio
6+
"""
7+
8+
# Función como argumento
9+
10+
11+
def apply_func(func, x):
12+
return func(x)
13+
14+
15+
print(apply_func(len, "MoureDev"))
16+
17+
# Retorno de función
18+
19+
20+
def apply_multiplier(n):
21+
def multiplier(x):
22+
return x * n
23+
return multiplier
24+
25+
26+
multiplier = apply_multiplier(2)
27+
print(multiplier(5))
28+
print(apply_multiplier(3)(2))
29+
30+
# Sistema
31+
32+
numbers = [1, 3, 4, 2, 5]
33+
34+
# map()
35+
36+
37+
def apply_double(n):
38+
return n * 2
39+
40+
41+
print(list(map(apply_double, numbers)))
42+
43+
# filter()
44+
45+
46+
def is_even(n):
47+
return n % 2 == 0
48+
49+
50+
print(list(filter(is_even, numbers)))
51+
52+
# sorted()
53+
54+
print(sorted(numbers))
55+
print(sorted(numbers, reverse=True))
56+
print(sorted(numbers, key=lambda x: -x))
57+
58+
# reduce()
59+
60+
61+
def sum_values(x, y):
62+
return x + y
63+
64+
65+
print(reduce(sum_values, numbers))
66+
67+
"""
68+
Extra
69+
"""
70+
71+
students = [
72+
{"name": "Brais", "birthdate": "29-04-1987", "grades": [5, 8.5, 3, 10]},
73+
{"name": "moure", "birthdate": "04-08-1995", "grades": [1, 9.5, 2, 4]},
74+
{"name": "mouredev", "birthdate": "15-12-2000", "grades": [4, 6.5, 5, 2]},
75+
{"name": "supermouredev", "birthdate": "25-01-1980",
76+
"grades": [10, 9, 9.7, 9.9]}
77+
]
78+
79+
80+
def average(grades):
81+
return sum(grades) / len(grades)
82+
83+
# Promedio
84+
85+
86+
print(
87+
list(map(lambda student: {
88+
"name": student["name"],
89+
"average": average(student["grades"])}, students)
90+
)
91+
)
92+
93+
# Mejores
94+
95+
print(
96+
list(
97+
map(lambda student:
98+
student["name"],
99+
filter(lambda student: average(student["grades"]) >= 9, students)
100+
)
101+
)
102+
)
103+
104+
# Fecha de nacimiento ordenada
105+
106+
print(sorted(students, key=lambda student: datetime.strptime(
107+
student["birthdate"], "%d-%m-%Y"), reverse=True))
108+
109+
# Califiación más alta
110+
111+
print(max(map(lambda student: max(student["grades"]), students)))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# #23 PATRONES DE DISEÑO: SINGLETON
2+
> #### Dificultad: Media | Publicación: 03/06/24 | Corrección: 10/06/24
3+
4+
## Ejercicio
5+
6+
```
7+
/*
8+
* EJERCICIO:
9+
* Explora el patrón de diseño "singleton" y muestra cómo crearlo
10+
* con un ejemplo genérico.
11+
*
12+
* DIFICULTAD EXTRA (opcional):
13+
* Utiliza el patrón de diseño "singleton" para representar una clase que
14+
* haga referencia a la sesión de usuario de una aplicación ficticia.
15+
* La sesión debe permitir asignar un usuario (id, username, nombre y email),
16+
* recuperar los datos del usuario y borrar los datos de la sesión.
17+
*/
18+
```
19+
#### Tienes toda la información extendida sobre el roadmap de retos de programación en **[retosdeprogramacion.com/roadmap](https://retosdeprogramacion.com/roadmap)**.
20+
21+
Sigue las **[instrucciones](../../README.md)**, consulta las correcciones y aporta la tuya propia utilizando el lenguaje de programación que quieras.
22+
23+
> Recuerda que cada semana se publica un nuevo ejercicio y se corrige el de la semana anterior en directo desde **[Twitch](https://twitch.tv/mouredev)**. Tienes el horario en la sección "eventos" del servidor de **[Discord](https://discord.gg/mouredev)**.

0 commit comments

Comments
 (0)