forked from M3-Academy/challenge-algorithms-v2.0
17 lines
294 B
JavaScript
17 lines
294 B
JavaScript
export function fibonacci(value) {
|
|
if (value < 1) return 0
|
|
if (value <= 2) return 1
|
|
let fibonnaci1 = 0
|
|
let fibonnaci2 = 1
|
|
let fibx = value
|
|
|
|
for (let i = 2; i <= value; i++) {
|
|
|
|
fibx = fibonnaci2 + fibonnaci1
|
|
fibonnaci1 = fibonnaci2
|
|
fibonnaci2 = fibx
|
|
}
|
|
|
|
return fibx
|
|
|
|
} |