forked from M3-Academy/challenge-algorithms-v2.0
Merge pull request 'feat(fibonacci): algoritmo criado.' (#4) from feature/algorithm04 into development
Reviewed-on: #4
This commit is contained in:
commit
db7e485577
@ -1,4 +1,17 @@
|
||||
export function fibonacci(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
if(value < 1) return 0;
|
||||
if(value <= 2) return 1;
|
||||
|
||||
let valorFib1 = 1;
|
||||
let valorFib2 = 0;
|
||||
let valorFibonacci = value;
|
||||
|
||||
for(let i = 2; i <= value; i++) {
|
||||
valorFibonacci = valorFib1 + valorFib2;
|
||||
valorFib2 = valorFib1;
|
||||
valorFib1 = valorFibonacci;
|
||||
}
|
||||
|
||||
return valorFibonacci;
|
||||
}
|
Loading…
Reference in New Issue
Block a user