From a41045308cb818e5d567d97ee5e887f42fb4548d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Casta=C3=B1eda?= Date: Sun, 5 Jan 2025 18:00:22 -0500 Subject: [PATCH 1/4] #34 - JavaScript --- .../javascript/victor-Casta.js" | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 "Roadmap/34 - \303\201RBOL GENEAL\303\223GICO LA CASA DEL DRAG\303\223N/javascript/victor-Casta.js" diff --git "a/Roadmap/34 - \303\201RBOL GENEAL\303\223GICO LA CASA DEL DRAG\303\223N/javascript/victor-Casta.js" "b/Roadmap/34 - \303\201RBOL GENEAL\303\223GICO LA CASA DEL DRAG\303\223N/javascript/victor-Casta.js" new file mode 100644 index 0000000000..ba9a7a293f --- /dev/null +++ "b/Roadmap/34 - \303\201RBOL GENEAL\303\223GICO LA CASA DEL DRAG\303\223N/javascript/victor-Casta.js" @@ -0,0 +1,106 @@ +class Person { + constructor(id, name) { + this.id = id + this.name = name + this.partner = null + this.children = [] + } +} + +class FamilyTree { + constructor() { + this.people = new Map() + } + + addPerson(id, name) { + if (this.people.has(id)) { + console.log(`La persona con ID ${id} ya existe.`) + return + } + const newPerson = new Person(id, name) + this.people.set(id, newPerson) + console.log(`Persona ${name} añadida al árbol.`) + } + + removePerson(id) { + if (!this.people.has(id)) { + console.log(`La persona con ID ${id} no existe.`) + return + } + + const person = this.people.get(id) + if (person.partner) { + person.partner.partner = null + } + + this.people.forEach((p) => { + p.children = p.children.filter((child) => child.id !== id) + }) + + this.people.delete(id) + console.log(`Persona con ID ${id} eliminada del árbol.`) + } + + setPartner(id1, id2) { + if (!this.people.has(id1) || !this.people.has(id2)) { + console.log(`Una o ambas personas no existen.`) + return + } + + const person1 = this.people.get(id1) + const person2 = this.people.get(id2) + + if (person1.partner || person2.partner) { + console.log(`Una de las personas ya tiene pareja.`) + return + } + + person1.partner = person2 + person2.partner = person1 + console.log(`${person1.name} y ${person2.name} ahora son pareja.`) + } + + addChild(parentId, childId) { + if (!this.people.has(parentId) || !this.people.has(childId)) { + console.log(`Una o ambas personas no existen.`) + return + } + + const parent = this.people.get(parentId) + const child = this.people.get(childId) + + if (!parent.children.includes(child)) { + parent.children.push(child) + console.log(`${child.name} añadido como hijo/a de ${parent.name}.`) + } else { + console.log(`${child.name} ya es hijo/a de ${parent.name}.`) + } + } + + printTree() { + this.people.forEach((person) => { + console.log(`ID: ${person.id}, Nombre: ${person.name}`) + if (person.partner) { + console.log(` Pareja: ${person.partner.name}`) + } + if (person.children.length > 0) { + const childNames = person.children.map((child) => child.name).join(", ") + console.log(` Hijos: ${childNames}`) + } + }) + } +} + +const tree = new FamilyTree() +tree.addPerson(1, "Alicent") +tree.addPerson(2, "Viserys") +tree.addPerson(3, "Rhaenyra") +tree.addPerson(4, "Daemon") + +tree.setPartner(1, 2) +tree.addChild(1, 3) +tree.setPartner(3, 4) + +tree.printTree() +tree.removePerson(3) +tree.printTree() \ No newline at end of file From f06f7252ffbf1b10554d5ae675d7bbbc5f9ca9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Casta=C3=B1eda?= Date: Sun, 5 Jan 2025 18:24:46 -0500 Subject: [PATCH 2/4] #16 - TypeScript --- .../typescript/victor-Casta.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Roadmap/16 - EXPRESIONES REGULARES/typescript/victor-Casta.ts diff --git a/Roadmap/16 - EXPRESIONES REGULARES/typescript/victor-Casta.ts b/Roadmap/16 - EXPRESIONES REGULARES/typescript/victor-Casta.ts new file mode 100644 index 0000000000..e10a1f72fa --- /dev/null +++ b/Roadmap/16 - EXPRESIONES REGULARES/typescript/victor-Casta.ts @@ -0,0 +1,9 @@ +const text: string = 'lor0em 9ip6sum 2 dolor 334, asit am3ed' +const getNumbersRegex: RegExp = /\d/g +console.log(text.match(getNumbersRegex)?.join('')) + +// extra + +const emailRegex: RegExp = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ +const phoneRegex: RegExp = /^\+?[1-9]\d{1,14}$/ +const urlRegex: RegExp = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ \ No newline at end of file From 444f1ff5de0a8a25fdc3feb8d59a9e6ef6254997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Casta=C3=B1eda?= Date: Sun, 5 Jan 2025 18:52:46 -0500 Subject: [PATCH 3/4] #17 - TypeScript --- .../typescript/victor-Casta.ts | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Roadmap/17 - ITERACIONES/typescript/victor-Casta.ts diff --git a/Roadmap/17 - ITERACIONES/typescript/victor-Casta.ts b/Roadmap/17 - ITERACIONES/typescript/victor-Casta.ts new file mode 100644 index 0000000000..eba4eeb792 --- /dev/null +++ b/Roadmap/17 - ITERACIONES/typescript/victor-Casta.ts @@ -0,0 +1,68 @@ +// 1. for +for(let i:number = 1; i <= 10; i++) { + console.log(i) +} + +// 2. while +let i:number = 1 +while (i <= 10) { + console.log(i) + i++ +} + +// 3. do while +let j: number = 1 +do { + console.log(j) + j++ +} while (j <= 10) + +// extra + + +const numbers: number[] = [1, 2, 3, 4, 5] + +// 4. for of +console.log("4. for...of") +for (const number of numbers) { + console.log(number) +} + +// 5. for in +console.log("5. for...in") +for (const index in numbers) { + console.log(numbers[index]) +} + +// 6. forEach +console.log("6. forEach") +numbers.forEach((number) => { + console.log(number) +}); + +// 7. map +console.log("7. map") +numbers.map((number) => { + console.log(number) +}); + +// 8. filter +console.log("8. filter") +numbers.filter((number) => { + console.log(number) + return true +}); + +// 9. reduce +console.log("9. reduce"); +numbers.reduce((_, number) => { + console.log(number) + return 0 +}, 0) + +// 10. every +console.log("10. every"); +numbers.every((number) => { + console.log(number) + return true +}) From 049b9a074f40876fa3eca0e952d0786dd2dfd387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Casta=C3=B1eda?= Date: Mon, 6 Jan 2025 18:46:16 -0500 Subject: [PATCH 4/4] #18 - TypeScript --- .../18 - CONJUNTOS/typescript/victor-Casta.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Roadmap/18 - CONJUNTOS/typescript/victor-Casta.ts diff --git a/Roadmap/18 - CONJUNTOS/typescript/victor-Casta.ts b/Roadmap/18 - CONJUNTOS/typescript/victor-Casta.ts new file mode 100644 index 0000000000..5cf36ba997 --- /dev/null +++ b/Roadmap/18 - CONJUNTOS/typescript/victor-Casta.ts @@ -0,0 +1,33 @@ +const myList: (number | number[])[] = [1,2,3,4] + +myList.push(5) +myList.unshift(0) +myList.push([10, 11, 12]) +myList[2] = [20, 21, 23] +myList.splice(0, 1) +myList[0] = 3 +myList.includes(3) +myList.length = 0 + +/* + Extra +*/ + +const mySet1: Set = new Set([1, 3, 5, 7, 9]) +const mySet2: Set = new Set([1, 4, 9]) + +// Unión +console.log(mySet1.union(mySet2)) + +// Intersección +console.log(mySet1.intersection(mySet2)) + +// Diferencia +console.log(mySet1.difference(mySet2)) + +// Diferencia simétrica +console.log(mySet1.symmetricDifference(mySet2)) + +/* + * Referencia: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set +*/ \ No newline at end of file