forked from M3-Academy/challenge-algorithms-v2.0
feat: criar algoritmo que realize a sequencia de fibonacci
This commit is contained in:
parent
1b9c0dbafe
commit
31c440491f
@ -1,4 +1,14 @@
|
||||
export function fibonacci(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
if (value < 1) return 0
|
||||
if (value <= 2) return 1
|
||||
let fib1 = 0
|
||||
let fib2 = 1
|
||||
let fibN = value
|
||||
for (let i = 2; i <=value; i++){
|
||||
fibN = fib2 + fib1
|
||||
fib1 = fib2
|
||||
fib2 = fibN
|
||||
}
|
||||
return fibN
|
||||
}
|
Loading…
Reference in New Issue
Block a user