-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[PTREMOTE] Maria Belen Colturi - lab-javascript-functions-and-arrays #3853
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
base: master
Are you sure you want to change the base?
Conversation
return null; | ||
} | ||
let longest = words[0]; | ||
for (let i = 0; i < words.length; i++) { |
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.
for (let i = 0; i < words.length; i++) { | |
for (let i = 1; i < words.length; i++) { |
Si te fijas la primera posicion ya la estas cogiendo antes, asi que compararla consigo misma pues como que no tiene mucho sentido jejeje
let sum = 0; | ||
for (let i = 0; i < numbers.length; i++) { | ||
const currentNumber = numbers[i] | ||
console.log(currentNumber); |
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.
console.log(currentNumber); |
Esto son pijadas pero vamos siempre que puedas quitar los console.log es bien :D
let sum = 0; | ||
for (let i = 0; i < numbers.length; i++) { | ||
currentNumber = numbers[i] | ||
sum += currentNumber | ||
} | ||
return sum |
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 metodo y el anterior de sumNumbers se parecen mucho, tirando a que son iguales, creo que en el ejercicio o los test te iba poniendo los diferentes puntos que tenias que tocar, por ejemplo si justo el elemento que estabas iterando era un string, o si era un booleano, objeto, etc
Miratelo si puedes y si tienes alguna duda me dices vale??
function averageNumbers() {} | ||
function averageNumbers(numbersAvg) { | ||
let average = 0; | ||
if (numbersAvg = [""]) { |
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.
if (numbersAvg = [""]) { | |
if (numbersAvg.length === 0) { |
Creo que en los test te dice si el array esta vacio, devuelve null, pues si te fijas tu habias igualado la variable (hubieses necesitado los tres iguales (===) para que fuera una pregunta buena buena jejej) y luego has preguntado porque el array tuviera una posicion y que en esa posicion tuviera un string vacio o "", por ello la mejor forma de saber si un array esta vacio es preguntar por su length y preguntar si ese length es 0, asi te aseguras que ese array AKA "bolsa" esta vacia, si no tiene nada pues esta vacia !!
for (let i = 0; i < numbersAvg.length; i++) { | ||
const element = numbersAvg[i]; | ||
average += element | ||
return average / numbersAvg.length | ||
} |
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.
for (let i = 0; i < numbersAvg.length; i++) { | |
const element = numbersAvg[i]; | |
average += element | |
return average / numbersAvg.length | |
} | |
for (let i = 0; i < numbersAvg.length; i++) { | |
const element = numbersAvg[i]; | |
average += element | |
} | |
return average / numbersAvg.length |
Si lo pones dentro del for, cuando pase una vez, pues ya no sale del bucle! por eso dejamos que el bucle termine y luego retornamos el resultado! :D
for (let i = 0; i < wordsArray.length; i++) { | ||
const word = wordsArray[i].length; | ||
wordAverage += word | ||
return wordAverage / wordsArray.length | ||
} |
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.
for (let i = 0; i < wordsArray.length; i++) { | |
const word = wordsArray[i].length; | |
wordAverage += word | |
return wordAverage / wordsArray.length | |
} | |
for (let i = 0; i < wordsArray.length; i++) { | |
const word = wordsArray[i].length; | |
wordAverage += word | |
} | |
return wordAverage / wordsArray.length |
Lo mismo que antes :D
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.
Gracias por los comentarios Cristian, voy a seguir practicando
This pull request has been automatically marked as stale because it didn't have any recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
No description provided.