diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 34e2e43..f316e95 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -3,5 +3,11 @@ export function fibonacci(value) { if(value <= 1){ return value } - return fibonacci(value - 1) + fibonacci(value - 2) + let v1 = 0, v2 = 1, v3 = 1; + for (let i = 2; i <= value ; i++) { + v3 = v1 + v2; + v1 = v2; + v2 = v3 + } + return v3; }