Skip to content

Commit 773c952

Browse files
authored
Merge branch 'mouredev:main' into main
2 parents a7f9a9f + f013b26 commit 773c952

File tree

17 files changed

+2058
-845
lines changed

17 files changed

+2058
-845
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Lloc web: https://www.java.com/es/
3+
*/
4+
// Comentario de una línea
5+
/* Comentario */
6+
/*
7+
* Comentario
8+
* de
9+
* varias
10+
* líneas
11+
*/
12+
13+
public class francescvm8 {
14+
public static void main(String[] args) {
15+
// declaración de variables
16+
String lenguaje = "Java";
17+
int numero = 1;
18+
boolean booleano = true;
19+
double decimal = 1.5;
20+
21+
// declaración de constante
22+
final String constante = "Hola";
23+
24+
// imprimir por terminal
25+
System.out.println("¡Hola, " + lenguaje + "!");
26+
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://python.org
2+
3+
# Esto es un comentario en una linea
4+
5+
"""
6+
Esto es un
7+
comentario en
8+
varias lineas
9+
"""
10+
my_variable = "Mi variable"
11+
my_variable = "Nuevo valor de mi variable"
12+
13+
MY_CONSTANT = "Mi constante" # por conveccion
14+
15+
my_int = 1
16+
my_float = 2.5
17+
my_bool = True
18+
my_bool = False
19+
my_string = "Mi cadena de texto"
20+
my_other_string" = 'Mi otra cadena de texto'
21+
22+
print("¡Hola, Python!")
23+
24+
print(type(my_int))
25+
print(type(my_float))
26+
print(type(my_bool))
27+
print(type(my_string))

Roadmap/03 - ESTRUCTURAS DE DATOS/javascript/1Nonamed.js

+115-16
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ const rl = readline.createInterface({ input, output });
7979

8080
const contacts = [
8181
{ id: 1, name: "Juan", phone: 1234560987 },
82-
{ id: 1, name: "Pedro", phone: 1234560987 },
82+
{ id: 1, name: "Juan", phone: 1222543388 },
83+
{ id: 2, name: "Pedro", phone: 1255566427 },
8384
];
8485

8586
const ops = [
@@ -89,34 +90,126 @@ const ops = [
8990
{ id: 4, name: "Delete" },
9091
];
9192

93+
const showAgenda = (arr) => {
94+
console.log(`
95+
*****************************************************
96+
* CONTACT LIST *
97+
*****************************************************`);
98+
arr.map((contact) =>
99+
console.log(` * Name: ${contact.name}
100+
* Phone: +57 ${contact.phone}
101+
-----------------------------------------------------`)
102+
);
103+
};
104+
105+
const isExit = async (op) => {
106+
const answer = await rl.question(`
107+
*****************************************************
108+
* *
109+
* Please select one of the following options: *
110+
* *
111+
* 1: Go back and try again *
112+
* 2: Go to the Main Menu *
113+
* 3: Show contact list and exit *
114+
* 0: Exit *
115+
* *
116+
*****************************************************
117+
* `);
118+
119+
if (+answer === 0) {
120+
rl.close();
121+
} else if (+answer === 1) {
122+
op();
123+
} else if (+answer === 2) {
124+
agenda();
125+
} else {
126+
showAgenda(contacts);
127+
rl.close();
128+
}
129+
};
130+
92131
const searchContact = async () => {
93132
console.log(`
94133
*****************************************************
95134
* SEARCH CONTACT *
96-
*****************************************************
97-
`);
98-
const contactInput = await rl.question("Contact name? ");
135+
*****************************************************`);
136+
const contactInput =
137+
await rl.question(` * Contact name? *
138+
* `);
99139

100-
const contact = contacts.find((contact) => {
101-
return contact.name === contactInput;
140+
const contactsFound = contacts.filter((contact) => {
141+
return contact.name.toLowerCase() === contactInput.toLowerCase();
102142
});
103143

104-
if (!contact) {
105-
console.log("Contact not found, please try again");
106-
searchContact();
144+
if (contactsFound.length === 0) {
145+
console.log(` * *
146+
* Contact not found. *`);
147+
isExit(searchContact);
107148
} else {
108-
console.log(contact);
149+
showAgenda(contactsFound);
150+
isExit(searchContact);
109151
}
110-
111-
agenda();
112152
};
113153

114-
const addContact = () => {
115-
console.log("Add");
154+
const addContact = async () => {
155+
console.log(`
156+
*****************************************************
157+
* ADD CONTACT *
158+
*****************************************************`);
159+
const contactInputName =
160+
await rl.question(` * Contact name? *
161+
* `);
162+
const contactInputPhone =
163+
await rl.question(` * *
164+
* Phone number? *
165+
* `);
166+
167+
const nameHasNumbers = /\d/.test(contactInputName);
168+
const phoneHasLetters = /[a-zA-Z]/g.test(contactInputPhone);
169+
170+
if (contactInputName === "" || nameHasNumbers) {
171+
console.log(`
172+
* Contact name is not valid. *
173+
* Only letters allowed. *`);
174+
isExit(addContact);
175+
} else if (
176+
contactInputPhone === "" ||
177+
phoneHasLetters ||
178+
contactInputPhone.length > 10
179+
) {
180+
console.log(`
181+
* Contact phone number is not valid. *
182+
* Only numbers allowed, has to be 10 digits *`);
183+
isExit(addContact);
184+
} else {
185+
const newContact = {
186+
id: contacts.length + 1,
187+
name: contactInputName,
188+
phone: +contactInputPhone,
189+
};
190+
191+
contacts.push(newContact);
192+
console.log(` *
193+
* The contact ${newContact.name} has been added sucessfully *`);
194+
isExit(addContact);
195+
}
116196
};
117-
const updateContact = () => {
118-
console.log("Update");
197+
198+
const updateContact = async () => {
199+
console.log(`
200+
*****************************************************
201+
* UPDATE CONTACT *
202+
*****************************************************`);
203+
const contactInputData =
204+
await rl.question(` * Contact to update? Type name or phone number
205+
* `);
206+
207+
const filteredContact = contacts.find((contact) => {
208+
contact.name === contactInputData || contact.phone === contactInputData;
209+
});
210+
console.log(` * Updating contact ${contactInputData}`);
119211
};
212+
120213
const deleteContact = () => {
121214
console.log("Delete");
122215
};
@@ -134,8 +227,10 @@ async function agenda() {
134227
* 2: Add Contact *
135228
* 3: Update Contact *
136229
* 4: Delete Contact *
230+
* 5: Show contact list *
137231
* *
138232
* 0: Exit program *
233+
* *
139234
*****************************************************
140235
141236
* Insert the operation number or 0 to exit: `
@@ -153,6 +248,10 @@ async function agenda() {
153248
case 4:
154249
deleteContact();
155250
break;
251+
case 5:
252+
showAgenda(contacts);
253+
isExit();
254+
break;
156255
case 0:
157256
rl.close();
158257
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
''' Asignación de variables'''
3+
4+
""" POR VALOR """
5+
6+
# Tipos inmutables - int, float, str, tuplas, bool
7+
8+
x = 10
9+
y = x # Se copia el valor de 'x' a 'y'
10+
y = 20 # Cambiar 'y' no afecta a 'x'
11+
12+
print(x)
13+
print(y)
14+
15+
""" POR REFERENCIA """
16+
17+
# Tipos mutables - list, dict, set
18+
19+
a = [1, 2, 3]
20+
b = a # Se asigna la referencia de 'a' a 'b'
21+
b.append(4) # Modificamos la lista usando 'b'
22+
23+
print(a)
24+
print(b)
25+
26+
''' Al ser mutables, tanto 'a' como 'b' apuntan al mismo objeto
27+
y cualquier cambio afecta a ambos
28+
'''
29+
30+
# Copiar por valor
31+
32+
a = [1, 2, 3]
33+
b = a.copy()
34+
b.append(4)
35+
36+
print(a)
37+
print(b)
38+
39+
# Funciones con datos por valor
40+
41+
def my_int_func(my_int: int):
42+
my_int = 20
43+
print(my_int)
44+
45+
my_int_c = 10
46+
my_int_func(my_int_c)
47+
print(my_int_c)
48+
49+
# Funciones con datos por referencia
50+
51+
def my_list_func(my_list: list):
52+
my_list_e = my_list
53+
my_list.append(30)
54+
55+
my_list_d = my_list_e
56+
my_list_d.append(40)
57+
58+
print(my_list_e)
59+
print(my_list_d)
60+
61+
my_list_c = [10, 20]
62+
my_list_func(my_list_c)
63+
print(my_list_c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class hernanR {
2+
public static void main(String[] args) {
3+
recursividad(100);
4+
System.out.println(factorial(5));
5+
}
6+
7+
public static void recursividad(int num) {
8+
if (num >= 0) {
9+
System.out.println(num);
10+
recursividad(num - 1);
11+
}
12+
}
13+
14+
public static int factorial(int num) {
15+
if (num == 0) {
16+
return 1;
17+
} else {
18+
return num * factorial(num - 1);
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* EJERCICIO:
3+
* Implementa los mecanismos de introducción y recuperación de elementos propios de las
4+
* pilas (stacks - LIFO) y las colas (queue - FIFO) utilizando una estructura de array
5+
* o lista (dependiendo de las posibilidades de tu lenguaje).
6+
*/
7+
8+
// Pilas (Stacks - LIFO) (Last In, First Out)
9+
const pilaDias = ["lunes", "martes", "miercoles", "jueves", "viernes"];
10+
//console.log(pilaDias);
11+
12+
pilaDias.push("sabado");
13+
//console.log(pilaDias);
14+
15+
pilaDias.pop();
16+
//console.log(pilaDias);
17+
18+
// Colas (Queues - FIFO) (First In, First Out)
19+
const colaDias = ["lunes", "martes", "miercoles", "jueves", "viernes"];
20+
21+
colaDias.push("sabado");
22+
//console.log(colaDias);
23+
24+
colaDias.shift();
25+
//console.log(colaDias);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* EJERCICIO:
3+
* Explora el concepto de clase y crea un ejemplo que implemente un inicializador,
4+
* atributos y una función que los imprima (teniendo en cuenta las posibilidades
5+
* de tu lenguaje).
6+
* Una vez implementada, créala, establece sus parámetros, modifícalos e imprímelos
7+
* utilizando su función.
8+
*
9+
*/
10+
11+
class automovil {
12+
constructor(marca, modelo, color) {
13+
this.marca = marca;
14+
this.modelo = modelo;
15+
this.color = color;
16+
}
17+
18+
imprimirAtributos() {
19+
return `Marca:${this.marca} Modelo:${this.modelo} Color:${this.color}`;
20+
}
21+
}
22+
23+
const ford = new automovil("Ford", "Focus", "Azul");
24+
const toyota = new automovil("Toyota", "Land Cruiser", "Blanco");
25+
26+
console.log(ford.imprimirAtributos());
27+
console.log(toyota.imprimirAtributos());
28+
29+
toyota.color = "gris";
30+
console.log(toyota.color);
31+
console.log(toyota);

0 commit comments

Comments
 (0)