Skip to content

Instantly share code, notes, and snippets.

@well1791
Created November 28, 2024 17:27
Show Gist options
  • Save well1791/7d2051203a4fb511d829c64fe1415276 to your computer and use it in GitHub Desktop.
Save well1791/7d2051203a4fb511d829c64fe1415276 to your computer and use it in GitHub Desktop.
nosenose1
class Identity {
#nombre;
constructor(nombre) {
this.#nombre = nombre;
}
getNombre() {
return this.#nombre;
}
}
class Profesor {
#nombre;
#materias;
/**
* @param {Identity} nombre
* @param {Materia[]} materias
*/
constructor(nombre, materias) {
this.#nombre = nombre;
this.#materias = materias;
}
getNombre() {
return this.#nombre.getNombre();
}
getMaterias() {
return this.#materias;
}
}
class Materia {
#nombre;
#requisitos;
/**
* @param {Identity} nombre
* @param {Materia[]} requisitos
*/
constructor(nombre, requisitos) {
this.#nombre = nombre;
this.#requisitos = requisitos;
}
getNombre() {
return this.#nombre.getNombre();
}
}
class Carrera {
#nombre;
#materias;
/**
* @param {Identity} nombre
* @param {Materia[]} materias
*/
constructor(nombre, materias) {
this.#nombre = nombre;
this.#materias = materias; // bd1, bd2
}
getProfesores() {
const result = this.#materias.map((mat) => {
const prof = profesores.find((prof) =>
prof
.getMaterias()
.some((profMat) => profMat.getNombre() === mat.getNombre()),
);
return prof ? prof.getNombre() : "---";
});
return result;
}
getProfesores2() {
const materias = this.#materias.map((mat) => mat.getNombre());
const result = profesores
.filter((prof) =>
prof.getMaterias().some((mat) => materias.includes(mat.getNombre())),
)
.map((prof) => prof.getNombre());
return result;
}
}
class Estudiante {
#nombre;
/**
* @param {Identity} nombre
*/
constructor(nombre) {
this.#nombre = nombre;
}
}
class Matricula {
#carrera;
#estudiante;
/**
* @param {Carrera} carrera
* @param {Estudiante} estudiante
*/
constructor(carrera, estudiante) {
this.#carrera = carrera;
this.#estudiante = estudiante;
}
}
//############################################################
const prof1 = new Identity("prof1");
const prof2 = new Identity("prof2");
const prof3 = new Identity("prof3");
const prof4 = new Identity("prof4");
const logica = new Identity("logica");
const bd1 = new Identity("bases de datos 1");
const bd2 = new Identity("bases de datos 2");
const oop = new Identity("object oriented programming");
const fp = new Identity("functional programming");
const htmlAndCss = new Identity("html and css");
const shell = new Identity("shell");
const git = new Identity("git");
const est1 = new Identity("estudiante1");
const est2 = new Identity("estudiante2");
const est3 = new Identity("estudiante3");
const est4 = new Identity("estudiante4");
const dataAnalysis = new Identity("data analysis");
const fe = new Identity("front end");
const sysAdmin = new Identity("sys admin");
const matLogica = new Materia(logica, []);
const matBd1 = new Materia(bd1, [matLogica]);
const matBd2 = new Materia(bd2, [matBd1]);
const matOop = new Materia(oop, [matLogica]);
const matFp = new Materia(fp, [matOop]);
const matHtmlCss = new Materia(htmlAndCss, []);
const matShell = new Materia(shell, []);
const matGit = new Materia(git, [matShell]);
const profLinux = new Profesor(prof1, [matShell, matGit]);
const profBd = new Profesor(prof2, [matBd1, matBd2]);
const profProg = new Profesor(prof3, [matOop, matFp]);
const profHtml = new Profesor(prof4, [matLogica, matHtmlCss]);
const profesores = [profLinux, profBd, profProg, profHtml];
const carrAnalisis = new Carrera(dataAnalysis, [
matLogica,
matBd1,
matBd2,
matOop,
]);
const carrFE = new Carrera(fe, [matLogica, matOop, matFp, matHtmlCss]);
const carrSysAdmin = new Carrera(sysAdmin, [
matLogica,
matOop,
matShell,
matGit,
]);
const estudiante1 = new Estudiante(est1);
const estudiante2 = new Estudiante(est2);
const estudiante3 = new Estudiante(est3);
const estudiante4 = new Estudiante(est4);
const matricula1 = new Matricula(carrAnalisis, estudiante1);
const matricula2 = new Matricula(carrFE, estudiante2);
const matricula3 = new Matricula(carrSysAdmin, estudiante3);
const matricula4 = new Matricula(carrFE, estudiante4);
//############################################################
const app = () => {
const result = carrFE.getProfesores();
const result2 = carrFE.getProfesores2();
console.log({ result, result2 });
};
app();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment