- Notifications
You must be signed in to change notification settings - Fork6.7k
MAD PT Cesar Aparicio#183
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//First Iteration | ||
function maxOfTwoNumbers(first, second){ | ||
if (first>second){ | ||
console.log(first); | ||
} | ||
else ("");{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. para los else no se necesita poner nada if(condición) { } else { } | ||
console.log(second); | ||
} | ||
} | ||
maxOfTwoNumbers (2 , 6); | ||
//Second Itaration | ||
// No me sale y no sé por qué: Tengo definida la array words, el siguiente paso veo que sea distinto de cero, obtengo la array válidad distinta de cero, recorro la array y pido que me devuelva el sumatorio partido la longitud y digo que me imprima el resultado de la funcion... pues nada, me sale undefined :( | ||
var words = [ | ||
"seat", | ||
"correspond", | ||
"linen", | ||
"motif", | ||
"hole", | ||
"smell", | ||
"smart", | ||
"chaos", | ||
"fuel", | ||
"palace" | ||
]; | ||
function avg(words) { | ||
if (words.length === 0 ) { | ||
return; | ||
} | ||
for (var sum=0, i=0; i <= words.length; i++) { | ||
sum += words[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. estás añadiendo la palabra a la variable sum, le estás diciendo que por ejemplo en la primera iteración "seat", sum += "0seat", luego "correspond", por lo que en la segunda iteración vale "0seatcorrespond" y así sucesivamente. Por lo que luego no puedes operar con un string | ||
} | ||
return sum/words.length; | ||
} | ||
console.log(avg([])); | ||
// Third Itaration | ||
var words = [ | ||
"mystery", | ||
"brother", | ||
"aviator", | ||
"crocodile", | ||
"pearl", | ||
"orchard", | ||
"crackpot" | ||
]; | ||
var differ = 0; | ||
//¿for(var i=0; esto es una variante de i = 0? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. sí, declaras una variable para el bucle for, aquí lo que harías es sobre escribir una variable que esté por encima en el código. Siempre declaralá dentro del bucle | ||
for (i = 0; i < words.length; i++) { | ||
if(words[i].length > differ) { | ||
var differ = words[i].length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. estás volviendo a declarar la variable con el nombre differ, por lo que estás sobreescribiendo la variable de la línea 51. si quieres asignar un valor a la variable de arriba deberías hacerlo sin la palabra reservada var | ||
words = words[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. en esta linea le estás diicnedo que "words" que es el array que estás iterando, vale la primera palabra del array en la primera iteración, por lo que luego el bucle iterará solo por las letras de esta palabra | ||
} | ||
} | ||
console.log(words); | ||
//imprime "mistery" cuando es "cocodrile" | ||
//Forth Iteration | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
function sum(numbers) { | ||
for (var sum=0, i=0; i < numbers.length; i++) { | ||
sum += numbers[i]; | ||
} | ||
return sum; | ||
} | ||
console.log (sum(numbers)); | ||
//Fifth Iteration | ||
var numbers = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
function sum(numbers) { | ||
for (var sum=0, i=0; i < numbers.length; i++) { | ||
sum += numbers[i]; | ||
} | ||
return sum/numbers.length; | ||
} | ||
console.log (sum(numbers)); | ||
//Sixth Iteration | ||
var words = ["crab", | ||
"poison", | ||
"contagious", | ||
"simple", | ||
"bring", | ||
"sharp", | ||
"playground", | ||
"poison", | ||
"communion", | ||
"simple", | ||
"bring"]; | ||
words = words.filter( function( item, index, inputArray ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. aquí no estás haciendo ninguna modificación, le estás pasando words, y le estás diciendo que te devuelva el mismo array, porque iterará sobre los elementos de este array uno a uno, y siempre coincide el index con la palabra buscada en el indexOf() | ||
return inputArray.indexOf(item) == index; | ||
}); | ||
// Seventh Iterantion | ||
var me = { | ||
name: "Julio", | ||
age: 24, | ||
email: "julio@ironhack.com", | ||
"role": "Developer", | ||
age: 30, | ||
key1: "fooooo", | ||
changeName: function(newName) { | ||
this.name = newName | ||
} | ||
}; |