-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: All iterations for lab functions and arrays js #3848
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?
Conversation
|
||
|
||
|
||
// Iteration #3: Calculate the sum | ||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
function sumNumbers() {} | ||
function sumNumbers(numbers) { |
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.
function sumNumbers(numbers) { | |
function sum(numbers) { |
Para que no te falle, el nombre de las funciones tiene que ser el que te venia por defecto si no falla los test de jasmine jejeje
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.
ahora mismo el codigo que tienes implementado solo suma numeros, es decir si te llega un string, o un array, o un objeto, o un booleano los intentas sumar todos, y eso no deberia ser asi, tienes que especificarlos un poco, te pongo como lo haria yo vale? y me dices cualquier cosa y lo vemos vale??
|
||
|
||
|
||
// Iteration #3: Calculate the sum | ||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
function sumNumbers() {} | ||
function sumNumbers(numbers) { | ||
if (numbers.length === 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.
if (numbers.length === 0) { | |
function sum(numbers) { | |
if (numbers.length === 0) { | |
return 0; | |
} | |
let sum = 0; | |
for (let i = 0; i < numbers.length; i++) { | |
if (typeof numbers[i] === "string") { | |
sum += numbers[i].length; | |
} else if (typeof numbers[i] === "number" || typeof numbers[i] === "boolean") { | |
sum += numbers[i]; | |
} else if (typeof numbers[i] === "object") { | |
throw new Error("Unsupported data type sir or ma'am"); | |
} | |
} | |
return sum; | |
} |
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.
Esto que te he puesto nada me he equivocado, seria para la funcion sum, no para sumNumbers, para sumNumbers estaba genial, pero si lo piensas bien, sum y sumNumbers son iguales, solo que sum tiene vitaminas jejeje
sum += numbers[i]; | ||
} | ||
|
||
const average = sum/ numbers.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.
const average = sum/ numbers.length; | |
const average = sum / numbers.length; |
soy un pijo....
|
||
// Bonus - Iteration #4.1 | ||
function avg() {} | ||
//function avg() {} |
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.
//function avg() {} | |
function avg() {} |
No te hace falta comentarlo, asi uno de los test no te falla jejeje
Esta genial! mirate los comentarios pero vamos genial!! |
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. |
van todas la iteraciones hechas sin los bonus como nos indicaron :)