-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
320 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
let a = 10; | ||
|
||
if (a >= 10) { // undefined, null, una asignación | ||
console.log('A es mayor o igual a 10'); | ||
} else { | ||
console.log('A es menor a 10'); | ||
} | ||
// console.log('Fin de programa') | ||
|
||
|
||
const hoy = new Date(); | ||
let dia = hoy.getDay(); // 0: Domingo, 1: lunes, 2: martes .... | ||
|
||
console.log({dia}); | ||
|
||
if (dia === 0){ | ||
console.log('Hoy es domingo'); | ||
} else if (dia === 1) { | ||
|
||
console.log('Lunes'); | ||
|
||
// if (dia ===1){ | ||
// console.log('Lunes') | ||
// } else { | ||
// console.log('No es lunes ni domingo') | ||
// } | ||
|
||
} else if (dia === 2) { | ||
console.log('Martes'); | ||
} else { | ||
console.log('No es lunes, martes o domingo...'); | ||
} | ||
|
||
// Sin usar If Else, o Switch, únicamente objetos | ||
// dia = 3; // 0: domingo | ||
|
||
const dias = { | ||
0: 'Domingo', | ||
1: 'Lunes', | ||
2: 'Martes', | ||
3: 'Miércoles', | ||
4: 'Jueves', | ||
5: 'Viernes', | ||
6: 'Sábado', | ||
} | ||
|
||
const diasConProcedimientos = { | ||
0: () => 'Domingo - 0', | ||
1: () => 'Lunes - 1', | ||
2: () => 'Martes - 2', | ||
3: () => 'Miércoles - 3', | ||
4: () => 'Jueves - 4', | ||
5: () => 'Viernes - 5', | ||
6: () => 'Sábado - 6', | ||
} | ||
|
||
const diasConArray = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; | ||
|
||
console.log(dias[dia] || 'Día no definido'); | ||
console.log(diasConProcedimientos[dia]() || 'Día no definido'); | ||
console.log(diasConArray[dia] || 'Día no definido'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const regresaTrue = () => { | ||
console.log('Regresa true'); | ||
return true; | ||
} | ||
|
||
const regresaFalse = () => { | ||
console.log('Regresa false'); | ||
return false; | ||
} | ||
|
||
console.warn('Not o la negación'); | ||
console.log(true); // true | ||
console.log(!true); // false | ||
console.log(false); // false | ||
console.log(!false); // true | ||
|
||
console.log(!regresaFalse()); // true | ||
|
||
console.warn('And'); // true si todos los valores son verdaderos | ||
console.log(true && true); // true | ||
console.log(true && !false); // true | ||
|
||
|
||
console.log('================'); | ||
|
||
console.log(regresaFalse() && regresaTrue()); // false | ||
console.log(regresaTrue() && regresaFalse()); // false | ||
|
||
|
||
console.log('=======&&======='); | ||
regresaFalse() && regresaTrue() | ||
|
||
console.log('4 condiciones:',true && true && true && true && false); // false | ||
|
||
console.warn('OR') // true si alguno de los valores son verdaderos | ||
|
||
console.log(true || false); // true | ||
console.log(false || false); // false | ||
|
||
console.log(regresaTrue() || regresaFalse()); // true | ||
console.log(regresaFalse() || regresaTrue()); // true | ||
console.log('4 condiciones:', true || true || true || true || false); // true | ||
|
||
console.warn('Asignaciones'); | ||
|
||
const soyUndefined = undefined; | ||
const soyNull = null; | ||
const soyFalso = false; | ||
|
||
const a1 = false && 'Hola Mundo' && 150; | ||
const a2 = 'Hola' && 'Mundo' && soyFalso; | ||
const a3 = soyFalso || 'Ya no soy falso'; | ||
const a4 = soyFalso || soyUndefined || soyNull || 'Ya no soy falso de nuevo' || true; | ||
const a5 = soyFalso || soyUndefined || regresaTrue() || 'Ya no soy falso de nuevo' || true; | ||
|
||
console.log({a1, a2, a3, a4, a5}); | ||
|
||
if ( regresaTrue() || regresaFalse() && (true || false || true) ){ | ||
console.log('Hacer algo'); | ||
} else { | ||
console.log('Hacer otra cosa'); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Dias de semana abrimos a las 11, | ||
* pero los fines de semana abrimos a las 9 | ||
*/ | ||
|
||
// Entra a un sitio web, para consultar si esta abierto hoy.... | ||
|
||
const dia = 1; // 0: Domingo... 1: Lunes.... | ||
const horaActual = 11; | ||
|
||
let horaApertura; | ||
let mensaje; // = (dia === 0 || dia === 6) ? 'Fin de semana' : 'Día de semana' // Esta abierto, Está cerrado, hoy abrimos a las XX | ||
|
||
// if (dia === 0 || dia === 6){ | ||
// if ( [0,6].includes(dia) ){ | ||
// console.log('Fin de semana'); | ||
// horaApertura = 9; | ||
// } else { | ||
// console.log('Día de semana'); | ||
// horaApertura = 11; | ||
// } | ||
|
||
//[0,6].includes(dia) ESTO es very good condition | ||
horaApertura = ([0,6].includes(dia)) ? 9 : 11; | ||
|
||
// if (horaActual >= horaApertura){ | ||
// mensaje = 'Esta abierto'; | ||
// } else { | ||
// mensaje = `Está cerrado, hoy abrimos a las ${horaApertura}`; | ||
// } | ||
|
||
mensaje = (horaActual >= horaApertura) ? 'Esta abierto' : `Está cerrado, hoy abrimos a las ${horaApertura}`; | ||
|
||
console.log({horaApertura, mensaje}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// const elMayor = (a, b) => { | ||
// return (a > b) ? a : b; | ||
// } | ||
const elMayor = (a, b) => (a > b) ? a : b; | ||
|
||
const tieneMembresia = (miembro) => (miembro) ? '2 Dólares' : '10 Dólares'; | ||
|
||
|
||
console.log(elMayor(20,15)); | ||
console.log(tieneMembresia(false)); | ||
|
||
|
||
const amigo = false; | ||
const amigosArr = [ | ||
'Peter', | ||
'Tony', | ||
'Dr. Strange', | ||
(amigo) ? 'Thor' : 'Loki', | ||
(() => 'Nick Fury')(), | ||
elMayor(10,15) | ||
]; | ||
|
||
console.log(amigosArr); | ||
|
||
const nota = 82.5; // A+ A B+ | ||
const grado = (nota >= 95) ? 'A+' : | ||
(nota >= 90) ? 'A' : | ||
(nota >= 85) ? 'B+' : | ||
(nota >= 80) ? 'B' : | ||
(nota >= 75) ? 'C+' : | ||
(nota >= 70) ? 'C' : 'F'; | ||
|
||
console.log({nota,grado}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const dia = 0; // 0: Domingo.. | ||
|
||
switch (dia) { | ||
case 0: | ||
console.log('Domingo'); break; | ||
case 1: | ||
console.log('Lunes'); break; | ||
case 2: | ||
console.log('Martes'); break; | ||
case 3: | ||
console.log('Miércoles'); break; | ||
case 4: | ||
console.log('Jueves'); break; | ||
case 5: | ||
console.log('Viernes'); break; | ||
case 6: | ||
console.log('Sábado'); break; | ||
default: | ||
console.log('No es un día válido'); break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
let a = 10; | ||
let b = a; | ||
a = 30; | ||
|
||
console.log(a,b); | ||
|
||
|
||
let juan = { nombre: 'Juan'}; | ||
let ana = {...juan}; | ||
ana.nombre = 'Ana'; | ||
|
||
console.log(juan,ana); | ||
|
||
const cambiaNombre = ({...persona}) => { | ||
persona.nombre = 'Tony'; | ||
return persona; | ||
} | ||
|
||
let peter = { nombre: 'Peter' }; | ||
let tony = cambiaNombre(peter); | ||
|
||
console.log({peter,tony}); | ||
|
||
|
||
// Arrays | ||
const frutas = ['Manzanas','Pera','Piña']; | ||
// const otrasFrutas = [...frutas]; | ||
console.time('slice'); | ||
const otrasFrutas = frutas.slice(); | ||
console.timeEnd('slice'); | ||
|
||
console.time('spread'); | ||
const otrasFrutas2 = [...frutas]; | ||
console.timeEnd('spread'); | ||
|
||
otrasFrutas.push('Mango'); | ||
|
||
console.table({frutas,otrasFrutas}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const heroes = ['Batman','Superman','Mujer Maravilla', 'Aquaman']; | ||
|
||
console.warn('For tradicional'); | ||
|
||
for( let i = 0; i < heroes.length; i++ ){ | ||
console.log(heroes[i]); | ||
} | ||
|
||
console.warn('For in'); | ||
for( let i in heroes ){ | ||
console.log(heroes[i]); | ||
} | ||
|
||
console.warn('For of'); | ||
for( let heroe of heroes ) { | ||
console.log(heroe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const coches = ['Ford','Mazda','Honda','Toyota']; | ||
|
||
let i = 0; | ||
|
||
// while( i < coches.length ){ | ||
// console.log(coches[i]); | ||
// // i = i + 1 | ||
// // i += 1; | ||
// i++; | ||
// } | ||
|
||
// Son Evaluados como un false y el while no se ejecutaria | ||
// | ||
// undefined | ||
// null | ||
// false | ||
|
||
// console.log(coches[10]); | ||
// while( i < coches.length ){ // Seria igual que el codigo de abajo, pero el de abajo es mas limpio, cuando i se salga del length del array devolveria un undefined que es lo mismo que un false en un while, por eso se detendria el while | ||
console.warn('While') | ||
while( coches[i] ){ | ||
if ( i === 1){ | ||
// break; | ||
i++; | ||
continue; | ||
} | ||
console.log(coches[i]); | ||
i++; | ||
} | ||
|
||
console.warn('Do While') | ||
|
||
let j = 0; | ||
|
||
do { | ||
console.log(coches[j]); | ||
j++; | ||
} while (coches[j]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters