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 de 0123]Miguel Ferragut#3569

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

Conversation

MiguelFerragut
Copy link

No description provided.

Copy link

@0xThales0xThales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Un lab un poco más complicado.
Te he dejado unos cuantos comentarios para solucionar algunos problemas y mejorar tu código.
Dale caña, esto es cuestión de enfrentarse al mismo problema cientos de veces. Cualquier cosa, me comentas. Un abrazo

Comment on lines +6 to +8
} else {
return num2
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Te sobra el else. Puede hacer directamente "return num2"

Comment on lines +21 to +23
if (words.length === 0) {
return null
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Dado que 0 es un valor falsy, este condicional podría refactorizarse de esta manera (más elegante y común en la industria):

if (!words.length) {    return null  }

Por otra parte, cuando el cuerpo de un condicional solo contiene una expresión, no es necesario servirse de bloques. Podemos refactorizar esa parte así (aplicable a cualquier parte del código):

if (!words.length) return null

Así queda un poco más limpio y organizado.




// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

function findLongestWord() {}
let longest = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Gran problema aquí!!!

  1. Si declaras la variable fuera de tu función, cuando el test se ejecuta no tiene acceso a esta... (Si vas al final del archivo verás que ahí se encuentran las exportaciones de tus funciones. En jest esas funciones se importan y se ejecutan pasando varios tests. Esos test no tienen acceso a NADA que no esté definido dentro de las funciones

  2. Es mejor definir la variable como una string vacía, tiene más sentido, ya que vas a sustituir el valor de esta por nuevas strings. Si no, das a entender que vas a usar ese array para algo. Simplemente define añadelet longest = "" dentro de tu función y ya estaría resuelto todo.

unique.push(element);
}

return unique

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Este return está dentro de tu for...
Tienes que pasarlo una línea más abajo.


let element = wordsUnique[i];

if (!unique.includes(element[i])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Aquí está el otro problema. Seríaif (!unique.includes(element))
"element" ya es wordsUnique[i]

for (let i = 0; i < wordsCount.length; i++) {
let word = wordsCount[i]

if (word.includes(wordsCount[i])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

wordsCount es tu array de palabras, no "word".

A la vez, includes solo busca la primera instancia de un elemento. Este método no te sirve para esta iteración.
Simplemente podrías comprobar la identidad estricta del elemento con "word". Si es el caso, entonces sumas 1. Una posible solución:

function howManyTimes(words, word) {  let times = 0  if (!words.length) {    return 0  }  for (e of words) {    if (e === word) times++  }  return times}

let times = 0

if (wordsCount.length === 0) {
return null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

retorna 0, no null

@MiguelFerragut
Copy link
Author

MiguelFerragut commentedJan 23, 2023 via email

Si que hice mal este,si...muchas gracias!El vie, 20 ene 2023 a las 12:08, Daniel Jimenez ***@***.***>)escribió:
***@***.**** commented on this pull request. Un lab un poco más complicado. Te he dejado unos cuantos comentarios para solucionar algunos problemas y mejorar tu código. Dale caña, esto es cuestión de enfrentarse al mismo problema cientos de veces. Cualquier cosa, me comentas. Un abrazo ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > + } else { + return num2 + } Te sobra el else. Puede hacer directamente "return num2" ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > + if (words.length === 0) { + return null + } Dado que 0 es un valor falsy, este condicional podría refactorizarse de esta manera (más elegante y común en la industria): if (!words.length) { return null } Por otra parte, cuando el cuerpo de un condicional solo contiene una expresión, no es necesario servirse de bloques. Podemos refactorizar esa parte así (aplicable a cualquier parte del código): if (!words.length) return null Así queda un poco más limpio y organizado. ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > // Iteration#2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +let longest = [] Gran problema aquí!!! 1. Si declaras la variable fuera de tu función, cuando el test se ejecuta no tiene acceso a esta... (Si vas al final del archivo verás que ahí se encuentran las exportaciones de tus funciones. En jest esas funciones se importan y se ejecutan pasando varios tests. Esos test no tienen acceso a NADA que no esté definido dentro de las funciones 2. Es mejor definir la variable como una string vacía, tiene más sentido, ya que vas a sustituir el valor de esta por nuevas strings. Si no, das a entender que vas a usar ese array para algo. Simplemente define añade let longest = "" dentro de tu función y ya estaría resuelto todo. ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > + + let unique = [] + + if (wordsUnique.length === 0) { + return null + } + + for (let i = 0; i < wordsUnique.length; i++) { + + let element = wordsUnique[i]; + + if (!unique.includes(element[i])) { + unique.push(element); + } + + return unique Este return está dentro de tu for... Tienes que pasarlo una línea más abajo. ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > @@ -52,14 +121,48 @@ const wordsUnique = [ 'bring' ]; -function uniquifyArray() {} +function uniquifyArray(wordsUnique) { + + let unique = [] + + if (wordsUnique.length === 0) { + return null + } + + for (let i = 0; i < wordsUnique.length; i++) { + + let element = wordsUnique[i]; + + if (!unique.includes(element[i])) { Aquí está el otro problema. Sería if (!unique.includes(element)) "element" ya es wordsUnique[i] ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > @@ -78,7 +181,23 @@ const wordsCount = [ 'matter' ]; -function howManyTimes() {} +function howManyTimes(wordsCount) { + + let times = 0 + + if (wordsCount.length === 0) { + return null + } + + for (let i = 0; i < wordsCount.length; i++) { + let word = wordsCount[i] + + if (word.includes(wordsCount[i])) { wordsCount es tu array de palabras, no "word". A la vez, includes solo busca la primera instancia de un elemento. Este método no te sirve para esta iteración. Simplemente podrías comprobar la identidad estricta del elemento con "word". Si es el caso, entonces sumas 1. Una posible solución: function howManyTimes(words, word) { let times = 0 if (!words.length) { return 0 } for (e of words) { if (e === word) times++ } return times } ------------------------------ In src/functions-and-arrays.js <#3569 (comment)> : > @@ -78,7 +181,23 @@ const wordsCount = [ 'matter' ]; -function howManyTimes() {} +function howManyTimes(wordsCount) { + + let times = 0 + + if (wordsCount.length === 0) { + return null retorna 0, no null — Reply to this email directly, view it on GitHub <#3569 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A5EOPB5FZNMY5MXKQOAEXLTWTJWZTANCNFSM6AAAAAAUAYR6TE> . You are receiving this because you authored the thread.Message ID: <ironhack-labs/lab-javascript-functions-and-arrays/pull/3569/review/1263313684 @github.com>

@stale
Copy link

stalebot commentedMar 25, 2023

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.

1 similar comment
@stale
Copy link

stalebot commentedMay 31, 2023

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.

@stalestalebot added the stale labelMay 31, 2023
@stale
Copy link

stalebot commentedJun 7, 2023

This pull request is closed. Thank you.

@stalestalebot closed thisJun 7, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@0xThales0xThales0xThales left review comments

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@MiguelFerragut@0xThales

[8]ページ先頭

©2009-2025 Movatter.jp