-
Notifications
You must be signed in to change notification settings - Fork 6
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
Ejercicios resueltos #1
base: main
Are you sure you want to change the base?
Ejercicios resueltos #1
Conversation
Ejercicios resueltos con todos los tests completados.
src/ejercicios.js
Outdated
} else if (n < 2) { | ||
return n | ||
} else { | ||
cache[n] = fibo(n - 1, cache) + fibo(n-2, cache) |
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.
Ojo con mutar cache acá, una forma más correcta sería
const newCache = [...cache]
newCache[n] = fibo(n - 1, cache) + fibo(n-2, cache)
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.
El tema es que si lo implemento así nunca finaliza el ultimo caso de los tests:
// si la función no termina, están calculando el resultado de una manera muy poco eficiente. expect(fns.fibo(100)).toEqual(354224848179262000000);
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.
@jabsatz Ahi le encontre una vuelta
const fibo = function() {
let cache = [];
return function fib(n) {
if (cache[n]) {
return cache[n]
} else if (n < 2) {
return n
} else {
cache[n] = fib(n - 1) + fib(n - 2)
}
return cache[n];
}
}()
Con el () llamo a la funcion fibo inmediamente, eso devuelve la funcion que regresa y cuando lo llamas en el test le pasas el numero directamente como parametro, y esa funcion que devuelve es la que es llamada en cada recursion.
src/ejercicios.js
Outdated
|
||
export const multiplicarAtributo = '???'; | ||
export const multiplicarAtributo = fp.curry((attr, obj) => { | ||
return obj[attr].reduce((acc, n) => acc * n); |
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.
está bien, pero fijate que estás repitiendo el código de atributo
y multiplicacion
. podés directamente usar esas funciones
src/ejercicios.js
Outdated
|
||
export const mayorPersona = '???'; | ||
export const mayorPersona = arr => { | ||
const firstElement = fp.first(fp.reverse(fp.sortBy(element => element['edad'], arr))) |
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.
lo mismo acá, podés usar ordenarPor
y atributo
Correcciones realizadas a 3 funciones siguiendo los lineamientos recibidos en la review
Ejercicios resueltos con todos los tests completados.