Skip to content

Ramírez Aguilar Marc #7

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions Clase8/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//Escoge los tipos de datos de las siguientes variables:
var edad = 20;
var nombre = "Juanito";
var producto = {
id: 20,
nombre: "Camiseta",
categorias: ["Primavera", "Verano"],
precio: 1202.23
};
//Crea la clase para esta instancia:
var Juguete = /** @class */ (function () {
function Juguete(id, nombre, color, precio) {
this._id = id;
this._nombre = nombre;
this.color = color;
this.precio = precio;
}
return Juguete;
}());
var soldadito = new Juguete();
soldadito.precio = 20;
console.log(soldadito.color);
var MiClase = /** @class */ (function () {
function MiClase() {
}
MiClase.prototype.deletrear = function (palabra) {
return palabra.split(" ");
};
MiClase.prototype.contar = function (palabra) {
return palabra.length;
};
MiClase.prototype.imprimir = function (mensaje) {
return "".concat(mensaje);
};
return MiClase;
}());
var LenguajeIngles = /** @class */ (function () {
function LenguajeIngles(caracteres) {
this.cantidadCaracteres = caracteres.length;
this.caracteres = caracteres;
}
LenguajeIngles.prototype.printNCaracteres = function (n) {
for (var caracter in this.caracteres) {
console.log(caracter);
}
};
return LenguajeIngles;
}());
function obtenerLongitudDeCadena(valorIngresado) {
console.log("Ingrese el valor a obtener el dato: " + valorIngresado);
var n = valorIngresado.length;
console.log("El tamaño del dato es: " + n);
}
//Crea UNA función que reciba un dato de tipo boolean o string o number y
//dependiendo del tipo imprima en consola "booleano" "cadena de caracteres" o "número"
//Respectivamente, usando generics;
//Nota: typeof nos regresa el tipo de dato de una variable
//Crear una clase Contenedor, que te permita: guardar, leer e imprimir todos sus items
//esta clase debe trabajar con un arreglo de items, estos items pueden ser de las siguientes
//interfaces: Juguete, Ropa, Botella o Libro
//Guardar: Se le pasa como parametro un objeto del tipo Juguete, Ropa,Botella o Libro y lo guarda en tu lista de items
//Leer: Se le pasa como parámetro el índice del item a regresar y lo retorna
//imprimir: No recibe parámetros e imprime todos tus items
//La clase debe implementar generics class Contenedor<T>{}
//para instanciarla: new Contenedor<Juguete | Ropa | Botella | Libro>();
//y probarla
142 changes: 136 additions & 6 deletions Clase8/exercises.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,63 @@
//Escoge los tipos de datos de las siguientes variables:
let edad = 20;
let nombre = "Juanito";
let producto = {
let edad2: number = 20;
let nombre: string = "Juanito";
let producto: {
id: number,
nombre: string,
categorias: string[],
precio: number
} = {
id: 20,
nombre: "Camiseta",
categorias: ["Primavera", "Verano"],
precio: 1202.23,
};

//Crea la clase para esta instancia:

/* class Juguete {
_color?: string
_precio?: number

set precio(_precio: number) {
this._precio = _precio ;
}

get color() {
if(this.color) {
return this.color ;
}
throw 'Color indefinido...' ;
}

} */

class Juguete {
_id?: string
_nombre?: string
color?: string
precio?: number

constructor(
id?: string,
nombre?: string,
color?: string,
precio?: number ) {
this._id = id ;
this._nombre = nombre ;
this.color = color ;
this.precio = precio ;
}
}

let soldadito = new Juguete();
soldadito.precio = 20;
console.log(soldadito.color);

//Crea las definiciones de las siguientes funciones:
type DefinicionDeletrear = ;
type DefinicionContar = ;
type DefinicionImprimir = ;
type DefinicionDeletrear = (palabra: string) => string[];
type DefinicionContar = (palabra: string) => number ;
type DefinicionImprimir = (palabra: string | number) => string ;

interface MisFuciones {
deletrear: DefinicionDeletrear;
Expand All @@ -40,6 +81,12 @@ class MiClase implements MisFuciones {

//Crea la interface correcta para esta clase, el constructor no está declarado en la interface

interface Lenguaje<T, U> {
cantidadCaracteres: number
caracteres: string[]
printNCaracteres(n: number): void
}

class LenguajeIngles implements Lenguaje<number, string> {
cantidadCaracteres: number;
caracteres: string[];
Expand All @@ -59,11 +106,46 @@ class LenguajeIngles implements Lenguaje<number, string> {
//Crea UNA función que te permita obtener la longitud de una cadena de caracteres o
//de algún arreglo que se le pase, solo admite arreglos o strings,usando Generics

type arregloOCadena = string | any[] ;

function obtenerLongitudDeCadena<T extends (arregloOCadena)>(valorIngresado: T) {
console.log("Ingrese el valor a obtener el dato: " + valorIngresado)
let n: number = valorIngresado.length ;
return 'El tamaño del dato es: ' + n ;
}

obtenerLongitudDeCadena('ESCOM') ;
obtenerLongitudDeCadena(['Koenissegg', 24, true])

//Crea UNA función que reciba un dato de tipo boolean o string o number y
//dependiendo del tipo imprima en consola "booleano" "cadena de caracteres" o "número"
//Respectivamente, usando generics;
//Nota: typeof nos regresa el tipo de dato de una variable

/* type T = number | string | boolean ,

function obtenerTipo<T>(valor: T) {
if(typeof valor == "boolean") {
console.log("Booleano.")
}
else if(typeof valor == "string") {
console.log("Cadena de caracteres.")
}
else if(typeof valor == "number") {
console.log("Número.")
}
}

*/

type NumeroCadenaBooleano = number | string | boolean ;

function obtenerTipoDeDato<U extends (NumeroCadenaBooleano)>(valorIngresado: U) {
console.log("Ingrese un dato (numero, cadena o booleano): " + valorIngresado) ;
let resultado = typeof valorIngresado ;
console.log('El tipo de dato es: ' + resultado)
}

//Crear una clase Contenedor, que te permita: guardar, leer e imprimir todos sus items
//esta clase debe trabajar con un arreglo de items, estos items pueden ser de las siguientes
//interfaces: Juguete, Ropa, Botella o Libro
Expand All @@ -73,3 +155,51 @@ class LenguajeIngles implements Lenguaje<number, string> {
//La clase debe implementar generics class Contenedor<T>{}
//para instanciarla: new Contenedor<Juguete | Ropa | Botella | Libro>();
//y probarla

type tiposDeItem = "juguete" | "ropa" | "botella" | "libro" ;

interface Item {
id: string
nombre: string
tipo: tiposDeItem
}

interface Juguete extends Item {}

interface Ropa extends Item {}

interface Botella extends Item {}

interface Libro extends Item {}

type items = Juguete | Ropa | Botella | Libro ;

class Contenedor <items> {
producto: items[] = []
constructor(item: items[]) {
this.producto = item ;
}

// Métodos.

guardar(item: items) {
console.log("Ingrese el nuevo dato en el arreglo: " + item)
this.producto.push(item) ;
return 'Producto ingresado correctamente...' ;
}

leer(indice: number) {
console.log("Ingrese el indice del dato: " + indice)
let resultado = this.producto[indice] ;
return resultado ;
}

imprimir() {
let indice: number;
for (indice = 0; indice < array.length; indice++) {
return this.producto[indice];
}
}
}

let contenedor = new Contenedor<items>([]) ;