-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,38 +1,91 @@ | ||||||||||||||||||||||
// Iteration #1: Find the maximum | ||||||||||||||||||||||
function maxOfTwoNumbers() {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function maxOfTwoNumbers(n1, n2) { | ||||||||||||||||||||||
if (n1 > n2) { | ||||||||||||||||||||||
return n1; | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
return n2; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Iteration #2: Find longest word | ||||||||||||||||||||||
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function findLongestWord() {} | ||||||||||||||||||||||
function findLongestWord(words) { | ||||||||||||||||||||||
if (words.length === 0) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
let longest = words[0]; | ||||||||||||||||||||||
for (let i = 0; i < words.length; i++) { | ||||||||||||||||||||||
if (words[i].length > longest.length) { | ||||||||||||||||||||||
longest = words[i]; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return longest; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Iteration #3: Calculate the sum | ||||||||||||||||||||||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function sumNumbers() {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function sumNumbers(numbers) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Esto son pijadas pero vamos siempre que puedas quitar los console.log es bien :D |
||||||||||||||||||||||
sum += currentNumber | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return sum | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Iteration #3.1 Bonus: | ||||||||||||||||||||||
function sum() {} | ||||||||||||||||||||||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function sum(numbers) { | ||||||||||||||||||||||
let sum = 0; | ||||||||||||||||||||||
for (let i = 0; i < numbers.length; i++) { | ||||||||||||||||||||||
currentNumber = numbers[i] | ||||||||||||||||||||||
sum += currentNumber | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return sum | ||||||||||||||||||||||
Comment on lines
+47
to
+52
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. 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?? |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Iteration #4: Calculate the average | ||||||||||||||||||||||
// Level 1: Array of numbers | ||||||||||||||||||||||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function averageNumbers() {} | ||||||||||||||||||||||
function averageNumbers(numbersAvg) { | ||||||||||||||||||||||
let average = 0; | ||||||||||||||||||||||
if (numbersAvg = [""]) { | ||||||||||||||||||||||
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.
Suggested change
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 !! |
||||||||||||||||||||||
return null | ||||||||||||||||||||||
} | ||||||||||||||||||||||
for (let i = 0; i < numbersAvg.length; i++) { | ||||||||||||||||||||||
const element = numbersAvg[i]; | ||||||||||||||||||||||
average += element | ||||||||||||||||||||||
return average / numbersAvg.length | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+65
to
+69
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.
Suggested change
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 |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Level 2: Array of strings | ||||||||||||||||||||||
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function averageWordLength() { } | ||||||||||||||||||||||
function averageWordLength(wordsArray) { | ||||||||||||||||||||||
let wordAverage = 0; | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (wordsArray.length === 0) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
for (let i = 0; i < wordsArray.length; i++) { | ||||||||||||||||||||||
const word = wordsArray[i].length; | ||||||||||||||||||||||
wordAverage += word | ||||||||||||||||||||||
return wordAverage / wordsArray.length | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+82
to
+86
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.
Suggested change
Lo mismo que antes :D 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. Gracias por los comentarios Cristian, voy a seguir practicando |
||||||||||||||||||||||
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Bonus - Iteration #4.1 | ||||||||||||||||||||||
function avg() {} | ||||||||||||||||||||||
|
@@ -52,9 +105,7 @@ const wordsUnique = [ | |||||||||||||||||||||
'bring' | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
function uniquifyArray() {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
function uniquifyArray(words) {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Iteration #6: Find elements | ||||||||||||||||||||||
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; | ||||||||||||||||||||||
|
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.
Si te fijas la primera posicion ya la estas cogiendo antes, asi que compararla consigo misma pues como que no tiene mucho sentido jejeje