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

16 lines
243 B
JavaScript

export function fibonacci(value) {
if(value < 1) return 0
if(value <= 2) return 1
let fib1 = 0
let fib2 = 1
let fibN = value
for (let i =1; i <=value; i++){
fibN = fib1 + fib2
fib2 = fib1
fib1 = fibN
}
return fibN
}