Skip to content

#24 - Python #4246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Roadmap/18 - CONJUNTOS/javascript/agusrosero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* EJERCICIO:
* Utilizando tu lenguaje crea un conjunto de datos y realiza las siguientes
* operaciones (debes utilizar una estructura que las soporte):
* - Añade un elemento al final.
* - Añade un elemento al principio.
* - Añade varios elementos en bloque al final.
* - Añade varios elementos en bloque en una posición concreta.
* - Elimina un elemento en una posición concreta.
* - Actualiza el valor de un elemento en una posición concreta.
* - Comprueba si un elemento está en un conjunto.
* - Elimina todo el contenido del conjunto.
*
* DIFICULTAD EXTRA (opcional):
* Muestra ejemplos de las siguientes operaciones con conjuntos:
* - Unión.
* - Intersección.
* - Diferencia.
* - Diferencia simétrica.
*/
const mySet = new Set();

// Añade un elemento
mySet.add(1);
mySet.add(2);
mySet.add(3);
// Añade varios elementos en bloque al final.
mySet.add([4, 5, 6]);
// Elimina un elemento en una posición concreta.
mySet.delete(3);
// Comprueba si un elemento está en un conjunto.
console.log(mySet.has(2));
console.log(mySet);

// DIFICULTAD EXTRA:
// Unión
conjunto1 = new Set([1, 2, 3, 4]);
conjunto2 = new Set([5, 6, 7, 8]);
const union = [...new Set([...conjunto1, ...conjunto2])];
console.log(union);

// Intersección
const firstSet = new Set([1, 2, 3, 4, 5]);
const secondSet = new Set([4, 5, 6, 7, 8]);
const commonElements = [...firstSet].filter((element) =>
secondSet.has(element)
);
const set = new Set(commonElements);
console.log(set);

// Diferencia
const firstSet2 = new Set([1, 2, 3, 4, 5]);
const secondSet2 = new Set([4, 5, 6, 7, 8]);

const diffElements = [...firstSet2].filter(
(element) => !secondSet2.has(element)
);
const set2 = new Set(diffElements);
console.log(set2);

// Diferencia simétrica
const firstSet3 = new Set([1, 2, 3, 4, 5]);
const secondSet3 = new Set([4, 5, 6, 7, 8]);

const firstOnlyElements = [...firstSet3].filter(
(element) => !secondSet3.has(element)
);
const secondOnlyElements = [...secondSet3].filter(
(element) => !firstSet3.has(element)
);
const set3 = new Set([...firstOnlyElements, ...secondOnlyElements]);
console.log(set3);
48 changes: 48 additions & 0 deletions Roadmap/24 - DECORADORES/python/agusrosero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
/*
* EJERCICIO:
* Explora el concepto de "decorador" y muestra cómo crearlo
* con un ejemplo genérico.
*
* DIFICULTAD EXTRA (opcional):
* Crea un decorador que sea capaz de contabilizar cuántas veces
* se ha llamado a una función y aplícalo a una función de tu elección.
*/
"""
# EJERCICIO:


def mi_decorador(fn):
def wrapper(*args, **kwargs):
print("Mi decorador...")
return fn(*args, **kwargs)
return wrapper


@mi_decorador
def suma(a, b):
return a + b


print(suma(10, 20))

# DIFICULTAD EXTRA:


def counter(fn):
def wrapper(*args, **kwargs):
wrapper.count += 1
return fn(*args, **kwargs)
wrapper.count = 0
return wrapper


@counter
def resta():
return 10 - 5


resta()
resta()
resta()
print(resta.count)