-
Notifications
You must be signed in to change notification settings - Fork 8
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
Añadir ejercicios clases 2, 3 y 4 #23
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¡Los ejercicios están perfectos Manuel! 👏
Te he puesto un comentario a modo de consejo, pero es mejora simplemente 😄
|
||
function ponPrimeraMayuscula(str) { | ||
let nuevoStr = ''; | ||
for (let palabra of str.split(' ')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El ejercicio está perfecto 😄
Esto es sólo un detalle, cuando en un for pones que sea en base a la ejecución de algo (str.split(' ')
en este caso), dicho código se ejecuta en cada iteración. Para pocas iteraciones sin problema, pero si tienes que iterar por un listado con muchos elementos, puede afectar al rendimiento de tu programa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No lo había pensado. Mejor guardar str.split(' ')
en una variable antes de empezar el bucle. Muchas gracias!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muy buen trabajo Manuel! te he puesto algunas sugerencias y hay un par de cosillas que repasar, pero en general están genial 🥳
const manejador = { | ||
set: (obj, prop, val) => { | ||
console.log(val); | ||
if (val.toUpperCase && val.toUpperCase() === "AQUAMAN") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bien vista esta comprobación 😄 el atributo length no es un string, así que no tiene ese método 👏
function getWeather(city) { | ||
const req = new XMLHttpRequest(); | ||
req.open('GET', `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=4e00db20c2d73fe030365db03138311c`, true); | ||
req.responseType = 'html'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aquí en vez de html sería json ya que es lo que devuelve la api 😬
const req = new XMLHttpRequest(); | ||
req.open('GET', `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=4e00db20c2d73fe030365db03138311c`, true); | ||
req.responseType = 'html'; | ||
req.onreadystatechange = function (event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esta función se ejecutará por cada cambio de estado del 1 al 4. Lo suyo es que la respuesta en sí la manejemos sólo cuando el readyState sea 4 😬
|
||
function fetchWeather(city) { | ||
const res = document.getElementById('res'); | ||
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=4e00db20c2d73fe030365db03138311c`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Te atreverías a pasar esta función a usar callbacks?
|
||
const cumple = new Date(2021, 7, 22); | ||
console.log(cumple.toLocaleDateString()); | ||
console.log(cumple.toLocaleDateString('uk')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
genial!
else if (!producto.precio || typeof producto.precio !== "number") { | ||
throw new Error("El precio es obligatorio y debe ser un número."); | ||
} | ||
let nombres = carrito.productos.map(p => p.nombre); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sólo como idea: aquí con un find/findIndex lo tendrías sin necesidad de iterar dos veces el array :-D
last = cur; | ||
return keep; | ||
}); | ||
return [first, ...todos]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aunque lo hayas acabado haciendo con Sets, estas soluciones están genial! 👏
function interseccion(...arrays) { | ||
let sets = arrays.map(array => new Set(array)); | ||
let todos = [].concat(...arrays); | ||
return Array.from(new Set(todos.filter(elemento => sets.every(set => set.has(elemento))))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este en realidad era para dos arrays sólo, así que es una maravilla que lo hayas resuelto para N 👏 🥇
No description provided.