-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[MAD PP Ángel Pérez y Esperanza Amaya] #515
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
Conversation
var longest = 0; | ||
for (var i = 0; i < array.length; i++) { | ||
if (array[i].length > longest) { | ||
longest = array[i].length; |
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.
Os falla un pequeño detalla, en lugar de guardar la longitud del string si guardáis directamente el string y tambien tenéis el return dentro del for, si lo sacáis funcionaría.
var longest = array[0];
for (var i = 1; i < array.length; i++) {
if (array[i].length > longest.length) {
longest = array[i];
}
}
return longest;
// Calculating a Sum | ||
|
||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
function sumArray(array) { | ||
if (array !== "") { |
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.
Os falla que no estáis retornando nada cuando hacéis el reduce, os faltaría después del else: return result
. y otro detalle, cuando estáis utilizando la propiedad reduce tenéis que darle un valor inicial. En total se os quedaría un código así.
if (array !== "") {
var result=array.reduce(function(a,b){
return a + b;
},0)
} else {
return 0;
}
return result;
// Calculate the Average | ||
|
||
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
||
function averageNumbers(array){ |
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.
Os pasa lo mismo que en de arriba, también tenéis que controlar si el la variable result tiene valor para poder dividirla, porque sino os darían error.
Y bueno, después de lo que os escribí arriba os faltan algunos detalles más. Si queréis que lo repasemos decírmelo y lo vemos despacio uno por uno. #Gabriel. |
No nos ha dado tiempo al bonus.
Tenemos problemas para que reconozca los empty arrays, a pesar de que el resto de función la recorre bien.
Tampoco hemos conseguido que reconozca en algunos casos un array de un único elemento.