fibonacci

This commit is contained in:
Maria Carolina Oliveira da Silva 2022-11-01 21:20:50 -03:00
parent 17e2ecc796
commit 895c95800f

View File

@ -1,4 +1,21 @@
export function fibonacci(value) { export function fibonacci(value) {
// implementar logica aqui // implementar logica aqui
if (value < 1) return 0
} if (value <= 2) return 1
let result = 0
let result2 = 1
let resultado = value
for ( let i =2; i <=value; i++){
resultado = result2 + result
result = result2
result2 =resultado
}
return resultado
}
console.log(fibonacci(0))
console.log(fibonacci(1))
console.log(fibonacci(2))
console.log(fibonacci(3))
console.log(fibonacci(4))
console.log(fibonacci(5))
console.log(fibonacci(6))