- Notifications
You must be signed in to change notification settings - Fork6.7k
BCN - Edu - Paula - ES#464
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.
Conversation
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.
Buen trabajo! Seguid currando! 💪
var index = 0; | ||
for (var i = 1; i < array.length; i++){ | ||
if (array[i].length>array[index].length){ | ||
index = 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.
Es un poco mas leíble si en vez de guardar el índice guardas el valor y devuelves la string directamente.... pero está ok jejej 👍
@@ -74,6 +140,17 @@ var wordsCount = [ | |||
'disobedience', | |||
'matter' | |||
]; | |||
function howManyTimes(array, word){ | |||
var counter = 0; |
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.
puedes añadir al principio:
if (array.length === 0) { return;}
Y así evitas ir al forEach innecesariamente.
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.
Pero solo debería haber un return, no?
Lo hemos hecho con "for" porque pensábamos que no podíamos usar una variable global fuera del "forEach" aunque estuviera dentro de la función que incluye el "forEach". Thor ya nos ha explicado que en este caso sí que se puede.
@Arkhanne