forked from M3-Academy/challenge-algorithms-v2.0
fix(04-fibonacci): created parameter memo
This commit is contained in:
parent
4552cc3b13
commit
1d2ca30337
@ -1,10 +1,9 @@
|
||||
export function fibonacci(value) {
|
||||
export function fibonacci(value,memo = {}) {
|
||||
// implementar logica aqui
|
||||
if(value < 0) return 0;
|
||||
if(value < 2) return value;
|
||||
if(memo[value]) return memo[value];
|
||||
let result = fibonacci(value - 1, memo) + fibonacci(value - 2, memo);
|
||||
memo[value] = result;
|
||||
console.log(memo);
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user