Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
CesarAp wants to merge3 commits intoironhack-labs:masterfromCesarAp:master
Closed
Show file tree
Hide file tree
Changes fromall 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
161 changes: 0 additions & 161 deletionsstarter-code/functions-and-arrays.js
View file
Open in desktop

This file was deleted.

117 changes: 117 additions & 0 deletionsstarter-code/lab-javascript-funtions-arrays-EXERCISES.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
//First Iteration

function maxOfTwoNumbers(first, second){
if (first>second){
console.log(first);
}
else ("");{
Copy link
Contributor

Choose a reason for hiding this comment

The 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];
Copy link
Contributor

Choose a reason for hiding this comment

The 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?
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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];
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
};

[8]ページ先頭

©2009-2025 Movatter.jp