diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..1cd2471 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,9 @@ -export function fibonacci(value) { +export function fibonacci(value, memo) { // implementar logica aqui - -} \ No newline at end of file + memo = memo || {} + + if (memo[value]) return memo[value] + if (value <= 1) return value + + return (memo[value] = fibonacci(value - 1, memo) + fibonacci(value - 2, memo)) +}