challenge-algorithms-v2.0-n.../04-fibonacci/index.js

14 lines
316 B
JavaScript
Raw Permalink Normal View History

export function fibonacci(value) {
// implementar logica aqui
2022-10-28 13:25:39 +00:00
if (value < 1) return 0
if (value <= 2) return 1
let fibMinus2 = 0
let fibMinus1 = 1
let fibN = value
for (let i = 2; i <=value; i++){
fibN = fibMinus1 + fibMinus2
fibMinus2 = fibMinus1
fibMinus1 = fibN
}
return fibN
}